examples/preact/pagination
| Name | Last commit message | Last commit date |
|---|---|---|
| .. | ||
README.md
TanStack Preact Query Pagination Example#
Paginated projects with placeholderData: keepPreviousData, so the current page stays visible while the next one loads. The next page is prefetched.
How it works#
src/services/projects/queries.tsdefinesprojectsQueries.list(page), aqueryOptionsfactory keyed by['projects', 'list', page]with a 5-secondstaleTime.src/App.tsxpasses it touseQuerywithplaceholderData: keepPreviousData. While the next page loads,datastill holds the previous page andisPlaceholderDataistrue, which disables the "Next Page" button.- When a page arrives with
hasMore: true, the next page is fetched ahead of time withqueryClient.query(projectsQueries.list(page + 1)). src/mocks.tsis an MSW handler for/api/projectsthat returns 10 projects per page after a 1-second delay, and setshasMoretofalseon the 10th page.
To run this example:
npm installnpm run dev