mirror of
https://github.com/TanStack/query.git
synced 2026-11-16 22:50:20 +00:00
* chore(*): adopt '@tanstack/oxlint-config' and '@tanstack/oxfmt-config', and fix the newly reported lint errors * chore(pnpm-lock.yaml): run 'pnpm dedupe' * chore(scripts): move 'oxlint/plugin.ts' to 'oxlint-plugin.ts' to match the flat layout of 'scripts' * chore(pnpm-workspace.yaml): update '@typescript-eslint/parser' and '@typescript-eslint/rule-tester' to '^8.72.1' to match the deduped '@typescript-eslint/utils' |
History
|
|
|---|---|---|
| .. | ||
| public | ||
| src | ||
| .gitignore | ||
| eslint.config.js | ||
| index.html | ||
| package.json | ||
| README.md | ||
| tsconfig.json | ||
| vite.config.ts | ||
TanStack React Query Suspense Example
Loads projects with suspense queries, and resets failed queries from an error boundary.
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.tsxare lazy-loaded and read their data withuseSuspenseQuery, so theReact.Suspensefallback insrc/index.tsxshows until the data and the component code are ready.- The "Show Projects" button in
src/index.tsxstartsqueryClient.query(projectsQueries.list()), and the "Load" button insrc/components/Projects.tsxstartsqueryClient.query(projectsQueries.detail(project.full_name)), before the state change that renders the component, so fetching runs in parallel with loading the component code. src/components/Button.tsxwraps clicks instartTransitionand shows a spinner while the transitionisPending.src/index.tsxwraps the boundary inQueryErrorResetBoundaryand passes itsresetto theErrorBoundaryfromreact-error-boundary, so "Try again" resets the failed queries before rendering again. TheQueryClientsetsretry: 0so errors show right away.
To run this example:
npm installnpm run dev