I can't, for the life of me, get `getPreviousPageParam` to work
I'm trying to use
useInfiniteQuery to create a simple paginated component that shows the results of the CURRENT page and allows to paginate back and forth with left/right buttons.
My REST API (DRF) is using the limit/offset approach rather than page/size, which may be related to the issue I'm having. To speed things up, I created a wrapper hook that simply allows me to specify the base URL and take care of the rest. Here's the code:
But I don't understand how getPreviousPageParam would work. How would having the first page only be useful? Maybe I'm adopting the wrong approach.
Thanks!2 Replies
absent-sapphire•3y ago
I wouldn't use useInfiniteQuery for this as you're just showing one page at a time, so it sounds more like a regular paginated query rather than an infinite query: https://tanstack.com/query/v4/docs/react/guides/paginated-queries
Paginated / Lagged Queries | TanStack Query Docs
Rendering paginated data is a very common UI pattern and in TanStack Query, it "just works" by including the page information in the query key:
adverse-sapphireOP•3y ago
Thanks Julien!