Skip to content

Latest commit

 

History

History
21 lines (16 loc) · 506 Bytes

use-intersection-observer.md

File metadata and controls

21 lines (16 loc) · 506 Bytes

useIntersectionObserver

Creates an IntersectionObserver to measure when a given ref element enters the viewport.

Example

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>