mirror of
https://github.com/blakeblackshear/frigate.git
synced 2025-12-07 14:04:10 +03:00
25 lines
462 B
TypeScript
25 lines
462 B
TypeScript
|
|
import { useEffect, useRef, useState } from "react";
|
||
|
|
|
||
|
|
const useImageLoaded = (): [
|
||
|
|
React.RefObject<HTMLImageElement>,
|
||
|
|
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;
|