jobiqo-cl
Version:
[](https://circleci.com/gh/jobiqo/jobiqo-cl)
25 lines (22 loc) • 657 B
JavaScript
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 };