usehooks-ts
usehooks-ts copied to clipboard
useIntersectionObserver return previous entry as well
It seems like it'd be generally useful to have the previous entry (or list of prev entries) returned from the hook. That way client code could compare timings, e.g.
const [ entry, prevEntry ] = useIntersectionObserver(ref, {})
const timeOnScreen = prevEntry ?? entry.time - prevEntry.time
or all previous entries like:
const { entry, previousEntries } = useIntersectionObserver(ref, {})
// ... do fancy comparisons
Hi, thanks for the feedback! I've pushed a PR that should fix it, feel free to give a code review on it. See #464
Amazing, thanks @juliencrn. I'll check it out!
Hey @juliencrn, I might have missed it but I don't see a way to get the previous entry with the new code.