UNPKG

@thibault.sh/hooks

Version:

A comprehensive collection of React hooks for browser storage, UI interactions, and more

2 lines 560 B
import {useState,useEffect}from'react';function f(e,{threshold:t=0,root:r=null,rootMargin:s="0%",freezeOnceVisible:c=!1}={}){let[n,u]=useState(null);return useEffect(()=>{let i=e==null?void 0:e.current;if(!i||c&&(n!=null&&n.isIntersecting))return;let o=new IntersectionObserver(([b])=>{u(b);},{threshold:t,root:r,rootMargin:s});return o.observe(i),()=>{o.disconnect();}},[e,t,r,s,c,n==null?void 0:n.isIntersecting]),n}export{f as useIntersectionObserver};//# sourceMappingURL=useIntersectionObserver.mjs.map //# sourceMappingURL=useIntersectionObserver.mjs.map