18 lines
364 B
TypeScript
18 lines
364 B
TypeScript
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;
|
|
imageCache.set(path, img);
|
|
|
|
return img;
|
|
});
|
|
|
|
return images;
|
|
};
|