fix(assets): cache in useImage

This commit is contained in:
2025-11-27 00:53:35 +01:00
parent 603e11808d
commit 311e6c23ac

View File

@@ -1,15 +1,16 @@
const imageCache = new Map<string, HTMLImageElement>();
export const useImages = (...paths: string[]) => {
const images = paths.map((path) => {
if (imageCache.has(path)) {
return imageCache.get(path)!;
}
const img = document.createElement("img");
img.src = path;
return img;
});
imageCache.set(path, img);
onBeforeUnmount(() => {
images.forEach((img) => {
img.src = "";
img.remove();
});
return img;
});
return images;