-
-
Notifications
You must be signed in to change notification settings - Fork 427
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
React 18: useIntersectionObserver loses binding when ref conditionally rendered #182
Comments
This is just because the dependency array in the useEffect in |
This still seems to be a problem for me even after the fix that changes the dep array for |
I have too this issue, seem a problem related with react 18 (and Next ? I use SSR), not sure. The ref is lost. It works on a page and not in anothers, I need to investigate more to understand the issue ... |
I think I see the issue. The hook has a deps array with
So, when we use Other libs (eg. |
Hi, thanks for the feedback! |
@juliencrn I can confirm that is still not working as expected in 3.1.0. If the observed element is conditionally rendered (rendered -> not rendered -> rendered) it simply stops working. Even the |
In the below example I'm passing in an infinite react-query hook into this component to load more results once the bottom of the list has been reached. With
useIntersectionObserver
this happens the first time, but after that, the binding is lost and theLoad more
button has to be clicked to initiate the fetching of the query. Tested on React 17 and works as expected.A better pattern might be to pass a ref from the hook to bind to a specific component, as is done here.
The text was updated successfully, but these errors were encountered: