T
TanStack3y ago
other-emerald

Implementing infinite scrolling without knowing the next page

Hey all. I’m new to tanstack query and I’m trying to implement an infinite query but the only thing is that the backend I’m working with does not return a next page param. The server accepts a skip and take params. What I currently do is keep a page counter in state and extrapolate the next skip and take value from that. What I’m struggling with is figuring out how to implement that with useInfiniteQuery. Has anyone done something similar and can you share any insights? Thanks!
2 Replies
frail-apricot
frail-apricot3y ago
you get all pages passed to getNextPageParam, so if you just want to increment, you can take allPages.length and go from there
other-emerald
other-emeraldOP3y ago
I should've figured it out earlier... The issue I was running into was that my infinite scroll was not working as expected. React Query is rock solid. Thank you, Dominik. I love what you are doing with RQ.

Did you find this page helpful?