a
This commit is contained in:
24
hooks/use-lazy-load.ts
Normal file
24
hooks/use-lazy-load.ts
Normal file
@@ -0,0 +1,24 @@
|
||||
import { useState, useEffect } from 'react';
|
||||
|
||||
let gameImages: { [id: string]: string } = {};
|
||||
|
||||
export function useGameThumbnailLazyLoad(img: string) {
|
||||
const [status, setStatus] = useState<string | undefined>(undefined);
|
||||
|
||||
useEffect(() => {
|
||||
const interval = setInterval(() => {
|
||||
if (gameImages[img]) {
|
||||
setStatus(gameImages[img]);
|
||||
clearInterval(interval);
|
||||
}
|
||||
}, 100);
|
||||
|
||||
return () => clearInterval(interval);
|
||||
}, []);
|
||||
|
||||
return status;
|
||||
}
|
||||
|
||||
export function addGameThumbnail(id: string, url: string) {
|
||||
gameImages[id] = url;
|
||||
}
|
||||
Reference in New Issue
Block a user