Skip to main content
Paginated queries allow users to navigate through data one page at a time. Unlike infinite queries, paginated queries replace the current page with the next or previous page.

Basic Pagination

Implement pagination using useQuery with a page parameter in the query key:
Each page is cached separately based on its unique query key ['projects', page]. This means navigating back to a previously viewed page will be instant if the data is still in cache.

Keeping Previous Data

Use placeholderData with keepPreviousData to prevent UI flickering when transitioning between pages:
isPlaceholderData will be true when showing previous data while the new page is loading. Use this to disable navigation buttons during transitions.

Prefetching Next Page

Improve perceived performance by prefetching the next page before the user clicks:
1

Check placeholder status

Only prefetch when not showing placeholder data to avoid prefetching the wrong page.
2

Check if more pages exist

Use your API’s hasMore or similar flag to determine if there’s a next page.
3

Prefetch the next page

Use queryClient.prefetchQuery() to fetch and cache the next page in the background.

Cursor-Based Pagination

For APIs using cursor-based pagination instead of page numbers:

Offset-Based Pagination

For APIs using offset and limit:
Implement traditional page number navigation:
Be careful when rendering many page number buttons. Consider showing only a subset of pages (e.g., first, last, current, and nearby pages) for large datasets.

Stale Time Configuration

Control how long paginated data stays fresh:
Setting a staleTime prevents unnecessary refetches when navigating between pages quickly. Each page’s staleness is tracked independently.

Comparing Pagination Strategies

Choose regular pagination for dashboards and admin panels where users need to jump between pages. Use infinite queries for feeds and content streams where users scroll continuously.