UNPKG

@faceless-ui/slider

Version:

A React library for building every kind of slider

33 lines 1.06 kB
import { useEffect, useState } from 'react'; export const useIntersection = (ref, options) => { const { root, rootMargin, threshold, } = options || {}; const [intersection, setIntersection] = useState({}); useEffect(() => { let observer; const { current: currentRef, } = ref; if (currentRef) { observer = new IntersectionObserver((entries) => { entries.forEach((entry) => { setIntersection(entry); }); }, { root: (root === null || root === void 0 ? void 0 : root.current) || null, rootMargin: rootMargin || '0px', threshold: threshold || 0.05, }); observer.observe(currentRef); } return () => { if (observer && currentRef) { observer.unobserve(currentRef); } }; }, [ ref, root, rootMargin, threshold, ]); return intersection; }; //# sourceMappingURL=useIntersection.js.map