2.0 alpha
These docs describe 2.0. Install it with @once-ui-system/core@alpha.
On 1.8.x? Read the 1.x docs
TrademarkTrademarkDocs
Ctrl k
Search docs...
Hooks

useInViewport

Updated: March 12, 2026
View on GitHub
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, Particle, HoloFx
  • 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":
Prop
Type
Default
ref
RefObject<HTMLElement | null>
options
IntersectionObserverInit{ threshold: 0 }
Returns a booleantrue when the element is intersecting the viewport, false otherwise.
Edit this page on GitHub
TrademarkTrademark
Built with curiosity by Lorant One and the Design Engineers Club