DOM & Events

useIntersectionObserver

Detect when elements enter or leave the viewport for lazy loading and animations.

import { useIntersectionObserver } from "saha-ui"

Uses

Detect element visibility with Intersection Observer. Also includes `useInfiniteScroll` helper that returns a sentinel ref.

Props

NameTypeDescriptionDefault
refRefObjectTarget element ref.-
optionsIntersectionObserverInitOptions such as threshold/rootMargin.-

Returns

NameDescription
isIntersectingBoolean whether element intersects viewport.

Example

const sentinelRef = useInfiniteScroll(loadMore, hasMore); <div ref={sentinelRef}>Loading...</div>

Notes

The infinite scroll hook observes the sentinel and calls your callback when it becomes visible.
Saha UI - The Modern React Component Library