mirror of
https://github.com/blakeblackshear/frigate.git
synced 2026-03-18 22:28:23 +03:00
fix useImageLoaded hook running on every render
This commit is contained in:
parent
34cc1208a6
commit
8aead4b2b1
@ -1,4 +1,4 @@
|
|||||||
import { useEffect, useRef, useState } from "react";
|
import { useCallback, useEffect, useRef, useState } from "react";
|
||||||
|
|
||||||
const useImageLoaded = (): [
|
const useImageLoaded = (): [
|
||||||
React.RefObject<HTMLImageElement | null>,
|
React.RefObject<HTMLImageElement | null>,
|
||||||
@ -8,15 +8,15 @@ const useImageLoaded = (): [
|
|||||||
const [loaded, setLoaded] = useState(false);
|
const [loaded, setLoaded] = useState(false);
|
||||||
const ref = useRef<HTMLImageElement>(null);
|
const ref = useRef<HTMLImageElement>(null);
|
||||||
|
|
||||||
const onLoad = () => {
|
const onLoad = useCallback(() => {
|
||||||
setLoaded(true);
|
setLoaded(true);
|
||||||
};
|
}, []);
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if (ref.current && ref.current?.complete) {
|
if (ref.current?.complete) {
|
||||||
onLoad();
|
onLoad();
|
||||||
}
|
}
|
||||||
});
|
}, [onLoad]);
|
||||||
|
|
||||||
return [ref, loaded, onLoad];
|
return [ref, loaded, onLoad];
|
||||||
};
|
};
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user