// in react project
useEffect(() => {
if (!hasNext) return;
const onScroll = (e: any) => {
if (window.scrollY + document.documentElement.clientHeight > document.documentElement.scrollHeight - 300) {
setDebounceCallback(() => fetchNextPage()); // I want to execute this function when the scroll is moved to a specific position
}
};
window.addEventListener('scroll', onScroll);
window.dispatchEvent(new CustomEvent('scroll'));
return () => {
window.removeEventListener('scroll', onScroll);
};
}, [hasNext]);
// in react project
useEffect(() => {
if (!hasNext) return;
const onScroll = (e: any) => {
if (window.scrollY + document.documentElement.clientHeight > document.documentElement.scrollHeight - 300) {
setDebounceCallback(() => fetchNextPage()); // I want to execute this function when the scroll is moved to a specific position
}
};
window.addEventListener('scroll', onScroll);
window.dispatchEvent(new CustomEvent('scroll'));
return () => {
window.removeEventListener('scroll', onScroll);
};
}, [hasNext]);