UNPKG

jobiqo-cl

Version:

[![CircleCI](https://circleci.com/gh/jobiqo/jobiqo-cl.svg?style=svg&circle-token=5a24efa5b8bbc4879276123e77d0d3f35ca7144c)](https://circleci.com/gh/jobiqo/jobiqo-cl)

25 lines (22 loc) 657 B
import { useEffect } from 'react'; const useIntersectionObserver = ({ root, target, onIntersect, threshold = 1.0, rootMargin = '0px' }) => { useEffect(() => { if (!root) { return; } const observer = new IntersectionObserver(onIntersect, { root: root.current, rootMargin, threshold }); if (!target) { return; } observer.observe(target.current); // Let's clean up after ourselves. return () => { observer.unobserve(target.current); }; }); }; export { useIntersectionObserver };