inView
A framework-agnostic utility that observes when a DOM element enters or leaves the viewport (or a scrollable container) using the IntersectionObserver API.
When the element enters view, onStart is called. If onStart returns a function, that function is called when the element leaves. Returns a cleanup function that disconnects the observer.
Use useInView instead when working inside React components.
Usage
One-shot (enter only)
If onStart returns nothing (undefined or void), the observer automatically unobserves the element after the first entry, useful for one-shot entrance animations:
Custom threshold
Scoped to a scrollable container
API
Parameters
Options
Return value
Returns a VoidFunction that unobserves the element and disconnects the observer when called.