Skip to Content
⭐️ Leave a star →
HooksuseIntersectionObserver

useIntersectionObserver

Observes intersection of an element with its scroll container (or the viewport by default). Returns the latest IntersectionObserverEntry, or null before the first callback. Use entry.isIntersecting for the common visibility check, or read the intersectionRatio / boundingClientRect fields for scroll-driven effects.

Set once: true to disconnect after the first intersection — useful for “load when visible” patterns.

import { useRef } from 'react' import { useIntersectionObserver } from '@wire-ui/react' function LazyImage({ src }: { src: string }) { const ref = useRef<HTMLDivElement>(null) const entry = useIntersectionObserver(ref, { threshold: 0.1, once: true }) const isVisible = entry?.isIntersecting ?? false return ( <div ref={ref} className="h-48 w-full"> {isVisible && <img src={src} alt="" />} </div> ) }

Parameters

ParamTypeDescription
refRefObject<Element | null>Element to observe.
optionsUseIntersectionObserverOptionsSee below.

Options

All native IntersectionObserverInit fields are supported in addition to:

OptionTypeDefaultDescription
rootElement | Document | nullviewportScroll container.
rootMarginstring'0px'Margin around the root.
thresholdnumber | number[]0Visibility thresholds.
oncebooleanfalseDisconnect after the first intersection.
enabledbooleantrueSkip observation while false.

Returns

IntersectionObserverEntry \| null — the latest entry, or null before the first callback.
Last updated on

MIT License © 2026 wire-ui

useIntersectionObserver – Wire UI