This repository was archived by the owner on Jan 10, 2025. It is now read-only.
Add hook-ey react-intersection-observer API#622
Merged
Conversation
cartogram
reviewed
Apr 1, 2019
| return [intersectionEntry, node]; | ||
| } | ||
|
|
||
| export function useValueTracking<T>( |
Contributor
There was a problem hiding this comment.
this makes sense as a shared hook https://github.com/Shopify/quilt/pull/609/files#diff-99a7b9f41d8c46ef5eb67c2b0da03b2aR3
Member
Author
There was a problem hiding this comment.
Yes, agreed, we just don't have a place for them yet, and I didn't want to throw that in here too.
marutypes
approved these changes
Apr 8, 2019
Contributor
marutypes
left a comment
There was a problem hiding this comment.
Some small (mostly documentation readability) comments, but this looks good overall to me.
| const [intersectionEntry, setIntersectingEntry] = useState< | ||
| IntersectionObserverEntry | ||
| >(() => ({ | ||
| boundingClientRect: emptyBoundingClientRect, |
Contributor
There was a problem hiding this comment.
should each of these maybe be clones instead of a reference to the same object?
Member
Author
There was a problem hiding this comment.
I don't think it matters, all the fields are meant to be readonly
packages/react-intersection-observer/src/test/IntersectionObserver.test.tsx
Outdated
Show resolved
Hide resolved
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to subscribe to this conversation on GitHub.
Already have an account?
Sign in.
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This PR adds a new
useIntersectionhook toreact-intersection-observer, and slightly reworks the API of the component version to feel more closely related. The README has all of the goods, but basically, the hook version just gives you the state + a ref to throw on a DOM node, so it's quite simple to use the hook version: