Files
frigate/web/src/hooks/use-image-loaded.ts
T

25 lines
469 B
TypeScript
Raw Normal View History

2024-02-26 12:34:52 -06:00
import { useEffect, useRef, useState } from "react";
const useImageLoaded = (): [
2026-03-05 08:42:38 -06:00
React.RefObject<HTMLImageElement | null>,
2024-02-26 12:34:52 -06:00
boolean,
() => void,
] => {
const [loaded, setLoaded] = useState(false);
const ref = useRef<HTMLImageElement>(null);
const onLoad = () => {
setLoaded(true);
};
useEffect(() => {
if (ref.current && ref.current?.complete) {
onLoad();
}
});
return [ref, loaded, onLoad];
};
export default useImageLoaded;