Hi i’m making an infinite scroll event to trigger new fetch on React Query, the problem is that i can’t find a way to type this on typescript
function onScroll(this: Document, ev: ScrollBehavior<EventListener>) {
const { scrollHeight, scrollTop, clientHeight } = ev.target.scrollingElement;
if (hasNextPage && scrollHeight - scrollTop <= clientHeight * 1.2) {
fetchNextPage();
}
}
>Solution :
event.target will never be document, you have to access document directly
function onScroll() {
const { scrollHeight, scrollTop, clientHeight } = document.scrollingElement;
if (hasNextPage && scrollHeight - scrollTop <= clientHeight * 1.2) {
fetchNextPage();
}
}