Make sure the current element is present before execution
This commit is contained in:
parent
e63d095468
commit
a9c83ed294
1 changed files with 4 additions and 2 deletions
|
@ -8,12 +8,14 @@ export const useOnScreen = (ref: React.MutableRefObject<HTMLElement>) => {
|
|||
);
|
||||
|
||||
React.useEffect(() => {
|
||||
observer.observe(ref.current);
|
||||
if (ref.current) {
|
||||
observer.observe(ref.current);
|
||||
}
|
||||
|
||||
return () => {
|
||||
observer.disconnect();
|
||||
};
|
||||
}, []);
|
||||
}, [ref.current]);
|
||||
|
||||
return isIntersecting;
|
||||
};
|
||||
|
|
Loading…
Reference in a new issue