0
Fork 0
mirror of https://github.com/TanStack/query.git synced 2026-11-16 22:50:20 +00:00
query/examples/react/suspense
Wonsuk Choi cb62f4f2ed
chore(*): adopt '@tanstack/oxlint-config' and '@tanstack/oxfmt-config', and fix the newly reported lint errors (#12555)
* 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 2026-11-16 22:25:25 +09:00
..
public docs(examples): Migrate suspense example to vite (#3953) 2022-08-11 17:54:42 +02:00
src chore(*): adopt '@tanstack/oxlint-config' and '@tanstack/oxfmt-config', and fix the newly reported lint errors (#12555) 2026-11-16 22:25:25 +09:00
.gitignore docs(examples): use each framework's template '.gitignore' in every example (#12592) 2026-11-13 10:57:29 +09:00
eslint.config.js chore(*): adopt '@tanstack/oxlint-config' and '@tanstack/oxfmt-config', and fix the newly reported lint errors (#12555) 2026-11-16 22:25:25 +09:00
index.html docs(examples): unify page titles to 'TanStack <Framework> Query <Name> Example' and remove scaffold leftovers (#12580) 2026-11-12 14:54:59 +09:00
package.json ci: Version Packages (#12543) 2026-11-07 00:00:45 +01:00
README.md docs(examples): rewrite the READMEs, add the framework or router to example titles, and rename examples to '<feature>-<framework>' (#12583) 2026-11-12 16:58:15 +09:00
tsconfig.json chore(examples/*/tsconfig): include '*.config.ts' and '*.config.js' like the packages (#12408) 2026-10-27 09:11:08 +09:00
vite.config.ts chore(*): adopt '@tanstack/oxlint-config' and '@tanstack/oxfmt-config', and fix the newly reported lint errors (#12555) 2026-11-16 22:25:25 +09:00

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.ts defines projectsQueries.list() and projectsQueries.detail(id) with queryOptions. src/services/projects/api.ts fetches TanStack repositories from the GitHub API and adds a 1-second delay.
  • src/components/Projects.tsx and src/components/Project.tsx are lazy-loaded and read their data with useSuspenseQuery, so the React.Suspense fallback in src/index.tsx shows until the data and the component code are ready.
  • The "Show Projects" button in src/index.tsx starts queryClient.query(projectsQueries.list()), and the "Load" button in src/components/Projects.tsx starts queryClient.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.tsx wraps clicks in startTransition and shows a spinner while the transition isPending.
  • src/index.tsx wraps the boundary in QueryErrorResetBoundary and passes its reset to the ErrorBoundary from react-error-boundary, so "Try again" resets the failed queries before rendering again. The QueryClient sets retry: 0 so errors show right away.

To run this example:

  • npm install
  • npm run dev