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

✨ Improve useIntersectionObserver #464

Merged
merged 4 commits into from
Feb 5, 2024

Conversation

juliencrn
Copy link
Owner

  • Updated the hook API (its signature) using function overloading to keep both the old and the new interface working together. The old one has been depreciated and will be removed in the incoming v3
    • from const entry = useIntersectionObserver(ref, options)
    • to const [ref, isIntersecting, entry] = useIntersectionObserver(options)
  • Support both object and tuple destructuring for the hook return
    • [ref, isIntersecting, entry]
    • { ref, isIntersecting, entry }
  • Refresh when the ref changes to always have the latest
  • Added onChange optional callback
  • Added initialIsIntersecting optional flag

This PR should fix #395, #271 and #182.
Open to code review!

@juliencrn juliencrn added bug Something isn't working enhancement Improvements labels Feb 2, 2024
Copy link

changeset-bot bot commented Feb 2, 2024

🦋 Changeset detected

Latest commit: 21ed1de

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 2 packages
Name Type
usehooks-ts Minor
www Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

Copy link
Contributor

@BlankParticle BlankParticle left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I tested the functionality of the hook, and things seems to work as expected

@juliencrn juliencrn merged commit f39078f into master Feb 5, 2024
3 checks passed
@juliencrn juliencrn deleted the feature/improve-use-intersection-observer branch February 27, 2024 18:42
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working enhancement Improvements
Projects
None yet
Development

Successfully merging this pull request may close these issues.

useIntersectionObserver return previous entry as well
2 participants