Open History to see the last commit
TanStack Solid Query Pagination Example (SolidStart)#
Paginated projects with placeholderData: keepPreviousData, so the current page stays visible while the next one loads. The next page is prefetched.
Built with SolidStart.
How it works#
src/services/projects/queries.tsdefinesprojectsQueries.list(page), aqueryOptionsfactory keyed by['projects', 'list', page]with a 5-secondstaleTime.src/services/projects/api.tsis a SolidStart server function marked with'use server'that returns 10 projects per page after a 1-second delay, withhasMore: page < 9, so the tenth page is the last one.src/routes/index.tsxpasses the options 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, acreateEffectfetches the next page ahead of time withqueryClient.query(projectsQueries.list(page() + 1)).
To run this example:
npm installnpm run dev