@thibault.sh/hooks
Version:
A comprehensive collection of React hooks for browser storage, UI interactions, and more
2 lines • 545 B
JavaScript
import {useState,useEffect}from'react';function v(n,{threshold:t=0,root:r=null,rootMargin:s="0%",freezeOnceVisible:c=!1}={}){let[e,u]=useState(null);return useEffect(()=>{let i=n.current;if(!i||c&&(e!=null&&e.isIntersecting))return;let o=new IntersectionObserver(([b])=>{u(b);},{threshold:t,root:r,rootMargin:s});return o.observe(i),()=>{o.disconnect();}},[n,t,r,s,c,e==null?void 0:e.isIntersecting]),e}export{v as useIntersectionObserver};//# sourceMappingURL=useIntersectionObserver.mjs.map
//# sourceMappingURL=useIntersectionObserver.mjs.map