TrademarkTrademark
Docs
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, ParticleFx, HoloFx

Features

  • Lightweight wrapper around IntersectionObserver
  • Returns a simple boolean — true when the element is in view
  • Accepts standard IntersectionObserverInit options
  • Cleans up automatically on unmount

Basic usage

Pass a ref to the hook and use the returned boolean to conditionally render or animate:

Custom threshold

Pass IntersectionObserverInit options as the second argument to customize when the element is considered "in viewport":

API reference

Type
Default
ref
RefObject<HTMLElement | null>—
options
IntersectionObserverInit{ threshold: 0 }

Return value

Returns a boolean — true 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