useScrollIntersect()function
useScrollIntersect(onEnter?: Nullish<Callback>, onLeave?: Nullish<Callback>): RefObject<T | null>
| Param | Type | |
|---|---|---|
onEnter | Nullish<Callback> | Called when the element becomes fully visible. |
onLeave | Nullish<Callback> | Called when the element stops being fully visible. |
| Return | |
|---|---|
RefObject<T | null> | A React ref to attach to the element to observe. |
Fire callbacks when a referenced element enters or leaves the visible scrolling area.
- Returns a
refto attach to the element you want to observe — typically the last item in a scrolling list, for infinite-scroll loading. - Uses an
IntersectionObserverwith a full-visibility threshold and disconnects it on unmount or when callbacks change.
Examples
const ref = useScrollIntersect(loadMore); return <div ref={ref} />;