The useInViewport hook uses the IntersectionObserver API to detect whether a referenced element is currently visible within the viewport. This is useful for pausing animations, lazy-loading content, or triggering effects only when elements are on screen.
Used in components: Mask, ParticleFx, HoloFx
Most animated components already use this hook internally to pause when off-screen. Use this hook directly when building custom components that need viewport awareness.
- Lightweight wrapper around IntersectionObserver
- Returns a simple boolean — true when the element is in view
- Accepts standard IntersectionObserverInit options
- Cleans up automatically on unmount
Pass a ref to the hook and use the returned boolean to conditionally render or animate:
Pass IntersectionObserverInit options as the second argument to customize when the element is considered "in viewport":
Returns a boolean — true when the element is intersecting the viewport, false otherwise.