Skip to content

Conversation

chapa
Copy link

@chapa chapa commented Feb 22, 2020

Fix #303

I'm not 100% sure of the need to use React.useLayoutEffect instead of React.useEffect, but it may be safer since we nee to execute the callback after the node has been removed from the ref by React (maybe after DOM mutations ?).

@codesandbox-ci
Copy link

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.

@coveralls
Copy link

Pull Request Test Coverage Report for Build 1724

  • 3 of 3 (100.0%) changed or added relevant lines in 1 file are covered.
  • No unchanged relevant lines lost coverage.
  • Overall coverage increased (+0.04%) to 98.974%

Totals Coverage Status
Change from base Build 1719: 0.04%
Covered Lines: 107
Relevant Lines: 107

💛 - Coveralls

@thebuilder
Copy link
Owner

Hey @chapa, thanks for making a PR for this. I have also been working on the fix myself, but not committed yet.

I would simply clear the state when the ref callback is called with a new (null) node. No need for an extra effect.

@chapa
Copy link
Author

chapa commented Feb 22, 2020

Of course !
You solution is much simpler, I didn't think the callback will be called on unmount 😄

@chapa chapa closed this Feb 22, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

inView stays true when component is unmounted
3 participants