usehooks-ts icon indicating copy to clipboard operation
usehooks-ts copied to clipboard

useIntersectionObserver return previous entry as well

Open devth opened this issue 1 year ago • 3 comments

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

devth avatar Nov 14 '23 15:11 devth

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

juliencrn avatar Feb 02 '24 14:02 juliencrn

Amazing, thanks @juliencrn. I'll check it out!

devth avatar Feb 02 '24 15:02 devth

Hey @juliencrn, I might have missed it but I don't see a way to get the previous entry with the new code.

devth avatar Feb 05 '24 14:02 devth