useIntersectionObserver
Observes changes in the intersection of a target DOM element with an ancestor element or the viewport.
Loading preview...
The useIntersectionObserver hook wraps the browser IntersectionObserver API to track when a target element enters or leaves the viewport (or a custom scroll container) and returns the latest IntersectionObserverEntry.
Installation
Usage
Examples
One-Time Reveal Animation (freezeOnceVisible)
Enable freezeOnceVisible: true to disconnect the observer as soon as the element becomes visible for the first time.
Reacting via onChange Callback
Use the onChange option to trigger side effects (such as analytics impression tracking) without needing an extra useEffect.
API Reference
UseIntersectionObserverOptions
Configuration options for IntersectionObserver thresholds, root container, and lifecycle callbacks.
Property
Specification
root?uniondefault:null
Ancestor element or document used as the viewport for checking visibility
Full Signature
rootMargin?stringdefault:'0px'
Margin around the
root elementFull Signature
threshold?uniondefault:0
Visibility ratio threshold(s) at which the observer callback fires
Full Signature
freezeOnceVisible?uniondefault:false
Stop observing once the target element has intersected at least once
Full Signature
enabled?uniondefault:true
Whether the observer is active
Full Signature
onChange?function
Callback fired whenever the intersection entry updates
Full Signature
Parameters
(entryIntersectionObserverEntry