(ref: RefObject<Element>, options?: IntersectionObserverInit)
| 6 | * @param options Intersection observer options |
| 7 | */ |
| 8 | export function useIntersectionObserver(ref: RefObject<Element>, options?: IntersectionObserverInit) { |
| 9 | const [isIntersecting, setIsIntersecting] = useState(false); |
| 10 | useEffect(() => { |
| 11 | const target = ref.current; |
| 12 | if (!target) return; |
| 13 | const observer = new IntersectionObserver(([entry]) => { |
| 14 | setIsIntersecting(entry.isIntersecting); |
| 15 | }, options); |
| 16 | observer.observe(target); |
| 17 | return () => { |
| 18 | observer.unobserve(target); |
| 19 | }; |
| 20 | }, [ref, options]); |
| 21 | return isIntersecting; |
| 22 | } |
nothing calls this directly
no outgoing calls
no test coverage detected