Last active: 2 years ago
const wrapper = useRef<HTMLDivElement>(null);
const obCallback: IntersectionObserverCallback = useCallback(
(entries, observer) => {
entries.forEach((entry) => {
if (!entry.isIntersecting) return;
if (!wrapper.current) return;
if (loading) return;
setPage((d) => {
d.pageCount = d.pageCount + pageCount;
});
observer.unobserve(wrapper.current);
});
},
[loading, setPage]
);
useEffect(() => {
const observer = new IntersectionObserver(obCallback);
wrapper.current && observer.observe(wrapper.current);
}, [loading, obCallback, page.pageCount, setPage]);