useIntersectionObserver

Observe element visibility in the viewport. Great for lazy loading, infinite scroll, and scroll animations.

import { useIntersectionObserver } from "@allem-sdk/hooks";

Parameters

PropTypeDefaultDescription
ref*RefObject<Element>Ref to the element to observe
options.thresholdnumber0Visibility threshold (0-1)
options.rootElement | nullnullScrollable ancestor
options.rootMarginstring"0px"Margin around root

Returns

boolean — Whether the element is intersecting the viewport.

Usage

const ref = useRef<HTMLDivElement>(null);
const isVisible = useIntersectionObserver(ref, { threshold: 0.5 });

<div ref={ref} className={isVisible ? "animate-in" : "opacity-0"}>
  Content appears when scrolled into view
</div>