Open History to see the last commit
1# TanStack Solid Query Suspense Example
2β
3Loads projects inside `<Suspense>`, with an error boundary for failed queries.
4β
5## How it works
6β
7- `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.
8- `src/components/Projects.tsx` and `src/components/Project.tsx` read the data with `useQuery` and `throwOnError: true`. Reading `data` inside `<Suspense>` suspends until the query resolves, and a spinner shows while `isFetching` is `true`.
9- `src/index.tsx` wraps the lazy-loaded components in `<Suspense>` and an `ErrorBoundary` whose "Try again" button calls `reset`. The `QueryClient` sets `retry: 0`, so errors reach the boundary right away.
10- Clicking "Show Projects" in `src/index.tsx` and "Load" in `src/components/Projects.tsx` starts the fetch with `queryClient.query(...)` before the component that needs the data renders.
11β
12To run this example:
13β
14- `npm install`
15- `npm run dev`