Skip to content

useIntersectionObserver ​

Category
Browser

Hook that gives you intersection observer state

typescript
import { useIntersectionObserver } from '@siberiacancode/reactuse';

Usage ​

typescript
const { ref, entry, inView } = useIntersectionObserver();

Demo ​

Api ​

Parameters

NameTypeDefaultNote
targetTarget-The target element to detect intersection
options.enabled?booleantrueThe IntersectionObserver options
options.onChange?((entries: IntersectionObserverEntry[], observer: IntersectionObserver) => void) | undefined-The callback to execute when intersection is detected
options.root?IntersectionObserverInit['root'] | RefObject<Element | null | undefined>-The root element to observe

Parameters

NameTypeDefaultNote
options.enabled?booleantrueThe IntersectionObserver options
options.onChange?((entries: IntersectionObserverEntry[], observer: IntersectionObserver) => void) | undefined-The callback to execute when intersection is detected
options.root?IntersectionObserverInit['root'] | RefObject<Element | null | undefined>-The root element to observe

Contributors ​

Source • Demo