mirror of
https://github.com/blakeblackshear/frigate.git
synced 2026-03-10 10:33:11 +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 = (): [
|
||||
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];
|
||||
};
|
||||
|
||||
Loading…
Reference in New Issue
Block a user