From a9c83ed294cf65c8e9c294adb26f2dfc6fef5259 Mon Sep 17 00:00:00 2001 From: Justin Date: Thu, 24 Mar 2022 11:06:01 -0400 Subject: [PATCH] Make sure the current element is present before execution --- app/soapbox/hooks/useOnScreen.ts | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/app/soapbox/hooks/useOnScreen.ts b/app/soapbox/hooks/useOnScreen.ts index 1ae207326..7cfd4f284 100644 --- a/app/soapbox/hooks/useOnScreen.ts +++ b/app/soapbox/hooks/useOnScreen.ts @@ -8,12 +8,14 @@ export const useOnScreen = (ref: React.MutableRefObject) => { ); React.useEffect(() => { - observer.observe(ref.current); + if (ref.current) { + observer.observe(ref.current); + } return () => { observer.disconnect(); }; - }, []); + }, [ref.current]); return isIntersecting; };