-
Notifications
You must be signed in to change notification settings - Fork 190
Clear inView status if ref is removed #306
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
Conversation
This pull request is automatically built and testable in CodeSandbox. To see build info of the built libraries, click here or the icon next to each commit SHA. Latest deployment of this branch, based on commit 38107b5:
|
Pull Request Test Coverage Report for Build 1727
💛 - Coveralls |
@thebuilder Hi. I don't think this was correctly back-ported to the hook. Try as I might, this does not behave properly with Looking at the code:
I placed My gut feeling is that the observed component is unmounted, thus triggering a call to |
My use case could be simplified to the usual todo list example:
However, picture a situation where I have a list of todos for each days of the week, and the user can select the day of the week.
|
OK so it seems like a known issue with refs and He suggested using Thanks |
Hey, thanks for the write up - The intention is that If there is a bug, then it could be that it doesn't correctly trigger the initial Intersection state on the new |
@thebuilder thanks for the quick reply. First, let me acknowledge that you have the most popular solution for using the Intersection Observer API with React, so if nobody complained, then my problem must be very niche for sure. I guess it might come down to different assumptions. Mine is that if the node is changed, then it is no longer the same node and since nothing is known about it then It's possible your assumption is that if the node is changed and both the previous node and the new node are visible on screen, then Going back to my
In the context of infinite scrolling, say our browser window right now can only show 10 todos.
Thanks |
@sebastienbarre try inspecting the The problem with changing it to flow you expect, is that it will require a double renderpass, to correctly reflect the state updates. It just opens the hook up for lots of race conditions and headaches. As an alternative, if the hook isn't working for you, use the observe() method directly in your own custom hook. This will give you full control over how you attach and remove the IntersectionObserver. |
Thanks. I guess what threw me off looking at the code is that the behavior I'm looking for is implemented in the
but it is not implemented in the hook, so they do not behave the same. Unfortunately using Thanks for your time. |
Make sure you correctly handle the ref callback, so it doesn't trigger infinite rerenders. |
This fixes #303 by clearing the
inView
status when theref
changes.