Skip to content
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

feat: rewrite internals to use setState for ref #573

Merged
merged 9 commits into from
Jul 22, 2022

Conversation

thebuilder
Copy link
Owner

Rewrite the internals of useInView to allow it to handle inline ref functions, without causing infinite loops.

  • Convert the useCallback ref function to a useState that triggers a useEffect.

Closes #572

@vercel
Copy link

vercel bot commented Jul 6, 2022

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Updated
react-intersection-observer ✅ Ready (Inspect) Visit Preview Jul 22, 2022 at 2:05PM (UTC)

@codesandbox-ci
Copy link

codesandbox-ci bot commented Jul 6, 2022

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 b6cecf6:

Sandbox Source
useInView Configuration
InView render props Configuration
InView plain children Configuration
dank-fog-4wm5cf Issue #572

@thebuilder thebuilder marked this pull request as ready for review July 6, 2022 11:40
@thebuilder
Copy link
Owner Author

Any comments on useInView changes @jjenzz?

Change it so cleanup is now done inside a `useEffect`. This allows the `setRef` to be called multiple times before the hook triggers the cleanup, ensuring the current `ref` is settled.
The flow is now contained in the useEffect
@thebuilder thebuilder merged commit 465754a into master Jul 22, 2022
@thebuilder thebuilder deleted the feat/state-batching branch July 22, 2022 15:27
@thebuilder
Copy link
Owner Author

🎉 This PR is included in version 9.4.0 🎉

The release is available on:

Your semantic-release bot 📦🚀

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

infinite loop caused by isInViewRef
2 participants