Skip to main content
Paginated queries are ideal for traditional page-based navigation (Page 1, 2, 3, etc.) where users navigate between discrete pages of data.

Basic Pagination Pattern

Using keepPreviousData

The keepPreviousData option is crucial for good pagination UX. Without it, you’d see a loading state between pages:
keepPreviousData keeps the previous query’s data until new data arrives, providing a smooth pagination experience without loading states.

Understanding isPlaceholderData

When using keepPreviousData, use isPlaceholderData to know when you’re showing old data:

Prefetching Next Page

Prefetch the next page for instant navigation:
Combining keepPreviousData with prefetching provides the best pagination UX: no loading states and instant page transitions.

Page-based vs Cursor-based

Page Numbers (Traditional)

Offset-based

Handling Total Pages

Server State Synchronization

Ensure pagination state stays in sync with URL:

Alternative: Custom Placeholder Data

You can also provide custom placeholder data:

Pagination with Filters

Combine pagination with filters in your query key:
Remember to reset to page 0 when filters change, otherwise users might land on an empty page.

Pagination Component Example

Pagination vs Infinite Queries

Choose the right pattern for your use case:

Next Steps