const observerRef = useRef<IntersectionObserver>();
const handleObserver = useCallback((entries: any[]) => {
const target = entries[0];
if (target.isIntersecting) {
console.log("intersecting");
}
}, []);
const loadMoreCallback = useCallback(
(el: HTMLDivElement) => {
if (observerRef.current) observerRef.current.disconnect();
const option: IntersectionObserverInit = {
root: null,
rootMargin: "0px",
threshold: 1.0,
};
observerRef.current = new IntersectionObserver(handleObserver, option);
if (el) observerRef.current.observe(el);
},
[handleObserver]
);