Make sure the current element is present before execution

This commit is contained in:
Justin 2022-03-24 11:06:01 -04:00
parent e63d095468
commit a9c83ed294

View file

@ -8,12 +8,14 @@ export const useOnScreen = (ref: React.MutableRefObject<HTMLElement>) => {
); );
React.useEffect(() => { React.useEffect(() => {
observer.observe(ref.current); if (ref.current) {
observer.observe(ref.current);
}
return () => { return () => {
observer.disconnect(); observer.disconnect();
}; };
}, []); }, [ref.current]);
return isIntersecting; return isIntersecting;
}; };