Merge branch 'fix-use-on-screen-hook' into 'next'
Make sure the current element is present before execution See merge request soapbox-pub/soapbox-fe!1141
This commit is contained in:
commit
76b72d9364
1 changed files with 4 additions and 2 deletions
|
@ -8,12 +8,14 @@ export const useOnScreen = (ref: React.MutableRefObject<HTMLElement>) => {
|
||||||
);
|
);
|
||||||
|
|
||||||
React.useEffect(() => {
|
React.useEffect(() => {
|
||||||
|
if (ref.current) {
|
||||||
observer.observe(ref.current);
|
observer.observe(ref.current);
|
||||||
|
}
|
||||||
|
|
||||||
return () => {
|
return () => {
|
||||||
observer.disconnect();
|
observer.disconnect();
|
||||||
};
|
};
|
||||||
}, []);
|
}, [ref.current]);
|
||||||
|
|
||||||
return isIntersecting;
|
return isIntersecting;
|
||||||
};
|
};
|
||||||
|
|
Loading…
Reference in a new issue