examples/svelte/pagination-sveltekit
| Name | Last commit message | Last commit date |
|---|---|---|
| .. | ||
README.md
TanStack Svelte Query Pagination Example (SvelteKit)#
Paginated projects with placeholderData: keepPreviousData, so the current page stays visible while the next one loads. The next page is prefetched.
Built with SvelteKit.
How it works#
src/lib/services/projects/queries.tsdefinesprojectsQueries.list(page), aqueryOptionsfactory keyed by['projects', 'list', page]with a 5-secondstaleTime.src/routes/+page.sveltepasses it tocreateQuerywithplaceholderData: 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, an$effectfetches the next page ahead of time withqueryClient.query(projectsQueries.list(page + 1)). src/routes/api/projects/+server.tsis a SvelteKit endpoint that returns 10 projects per page after a 1-second delay.
To run this example:
npm installnpm run dev