Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

How can i type this scroll event

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 :

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

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();
  }
}
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading