Size
0.67 kb
useIntersectionObserver
The IntersectionObserver API, reactified, simplified and optimized.
Features
- Instance Reuse: Optimizes performance by reusing IntersectionObserver instances based on options.
 - Convenient Unwrapping: Automatically unwraps the entries parameter, allowing direct access to each entry in the callback.
 - Manual Observation Control: Allows manual control over observation using the 
observeandunobservefunctions. 
Installation
Usage
Observe an element's intersection with the viewport:
Customize the intersection observer:
Stop observing the target after the first intersection:
API Reference
UseIntersectionObserverOptions
Options for the useIntersectionObserver hook.
| Prop | Type | Default | 
|---|---|---|
autoObserve? | boolean | true | 
threshold? | number | number[] | - | 
rootMargin? | string | - | 
root? | Element | Document | null | - | 
UseIntersectionObserverReturn
Return value for the useIntersectionObserver hook.
| Prop | Type | Default | 
|---|---|---|
target | Element | null | - | 
ref | Function | - | 
unobserve | () => void | - | 
observe | () => void | - |