T
TanStack4y ago
optimistic-gold

How can i handle server driven pagination

i have a backend that responds with data AND pagination. Should I keep the paginated data in local state , even though it is managed from react query as well? im a little confused on this
5 Replies
optimistic-gold
optimistic-goldOP4y ago
Hello, I would love to push this up because this is a pattern I’ve seen in multiple apps (server driven pagination) and don’t really know how to move with react query :/
quickest-silver
quickest-silver4y ago
infinite queries do exactly this
optimistic-gold
optimistic-goldOP4y ago
@TkDodo 🔮 great! i just managed to actually go quite far with them. Another question i have now is, is there a way to type the pageParam so that i can also define it for the fetchNextPage? i guess this would actually move up the stack and be added to several other parts, like in data.pageParams?
quickest-silver
quickest-silver4y ago
sadly, no. This would require another generic because pageParam an be anything and we haven't implemented that. Also, you can work with a manual mode where you don't provide getNextPageParam, but pass the pageParam directly to fetchNextPage
optimistic-gold
optimistic-goldOP4y ago
yeah, thats what i assumed. i think ill create a wrapper around fetchNextPage and then add the types myself

Did you find this page helpful?