fix useImageLoaded hook running on every render

This commit is contained in:
Josh Hawkins 2026-03-05 21:05:54 -06:00
parent 34cc1208a6
commit 8aead4b2b1

View File

@ -1,4 +1,4 @@
import { useEffect, useRef, useState } from "react";
import { useCallback, useEffect, useRef, useState } from "react";
const useImageLoaded = (): [
React.RefObject<HTMLImageElement | null>,
@ -8,15 +8,15 @@ const useImageLoaded = (): [
const [loaded, setLoaded] = useState(false);
const ref = useRef<HTMLImageElement>(null);
const onLoad = () => {
const onLoad = useCallback(() => {
setLoaded(true);
};
}, []);
useEffect(() => {
if (ref.current && ref.current?.complete) {
if (ref.current?.complete) {
onLoad();
}
});
}, [onLoad]);
return [ref, loaded, onLoad];
};