Open History to see the last commit
1# TanStack Vue Query Suspense Example
2β
3Loads projects in async components that `await` the query's `suspense()` inside `<Suspense>`.
4β
5## How it works
6β
7- `src/services/projects/queries.ts` defines `projectsQueries.list()` and `projectsQueries.detail(id)`, `queryOptions` factories for TanStack repositories on the GitHub API. `src/services/projects/api.ts` adds a 1-second delay to each request.
8- `src/components/ProjectList.vue` and `src/components/ProjectDetail.vue` call `useQuery` with `throwOnError: true` and then `await suspense()` in `<script setup>`, which makes them async components that suspend until the data arrives.
9- `src/App.vue` loads both with `defineAsyncComponent` inside `<Suspense>`, shows the `#fallback` slot while they suspend, and catches query errors with `onErrorCaptured`.
10- Fetches start before the component suspends: `src/App.vue` calls `queryClient.query(projectsQueries.list())` when showing the projects, and `src/components/ProjectList.vue` calls `queryClient.query(projectsQueries.detail(project))` when a project is clicked.
11- `src/transition.ts` provides an `isPending` ref that `<Suspense>` sets from its `pending` and `resolve` events, and `src/components/BaseButton.vue` uses it to show a spinner on the clicked button.
12β
13To run this example:
14β
15- `npm install`
16- `npm run dev`