I want to show a skeleton while my image is loading. I tried to pass an onLoad
prop in the new Image
component provided by NextJS but the function fires off before the image is loaded.
Here is my code
const [loaded, setLoaded] = useState(false);
<Image
src={src}
alt={""}
className={styles.image_tag}
onLoad={(e) => setLoaded(true)}
style={{ opacity: loaded ? "1" : "0" }}
layout={"fill"}
/>
{!loaded && (
<Skeleton
className={styles.skeleton}
variant={"rect"}
animation={"wave"}
/>
)}