Creates an IntersectionObserver
to measure when a given ref element enters the viewport.
const ref = useRef(null);
useIntersectionObserver({
ref
threshold: [0, 1],
handleEntry: (entry) => {
if ((entry?.isIntersecting) {
// do something upon intersection!
}
},
}, [/* effect dependencies */]);
<div ref={ref}>Watch me with IntersectionObserver</div>