examples/solid/suspense
| Name | Last commit message | Last commit date |
|---|---|---|
| .. | ||
README.md
TanStack Solid Query Suspense Example#
Loads projects inside <Suspense>, with an error boundary for failed queries.
How it works#
src/services/projects/queries.tsdefinesprojectsQueries.list()andprojectsQueries.detail(id)withqueryOptions.src/services/projects/api.tsfetches TanStack repositories from the GitHub API and adds a 1-second delay.src/components/Projects.tsxandsrc/components/Project.tsxread the data withuseQueryandthrowOnError: true. Readingdatainside<Suspense>suspends until the query resolves, and a spinner shows whileisFetchingistrue.src/index.tsxwraps the lazy-loaded components in<Suspense>and anErrorBoundarywhose "Try again" button callsreset. TheQueryClientsetsretry: 0, so errors reach the boundary right away.- Clicking "Show Projects" in
src/index.tsxand "Load" insrc/components/Projects.tsxstarts the fetch withqueryClient.query(...)before the component that needs the data renders.
To run this example:
npm installnpm run dev