Warning: The ref value 'lastBookmarkRef.current' will likely have changed by the time this effect cleanup function runs. If this ref points to a node rendered by React, copy 'lastBookmarkRef.current' to a variable inside the effect, and use that variable in the cleanup function.
useEffect(() => {
const observer = new IntersectionObserver(([entry]) => {
if (entry.isIntersecting) {
setPage((prevPage) => prevPage + 1)
}
})
if (lastBookmarkRef.current) {
observer.observe(lastBookmarkRef.current)
}
return () => {
if (lastBookmarkRef.current) {
observer.unobserve(lastBookmarkRef.current)
}
}
}, [])