Open History to see the last commit
1# TanStack Vue Query Simple Example (Nuxt 4)
2β
3Fetches a single GitHub repository and shows its stats.
4β
5Built with [Nuxt 4](https://nuxt.com).
6β
7## How it works
8β
9- `app/services/repos/queries.ts` defines `reposQueries.detail()`, a `queryOptions` factory keyed by `['repos', 'detail']` that fetches the `TanStack/query` repository from the GitHub API.
10- `app/app.vue` reads it with `useQuery(reposQueries.detail())` and calls `await suspense()` in `<script setup>`, so the repository is fetched during server rendering.
11- `app/plugins/vue-query.ts` is a Nuxt plugin that creates a `QueryClient` with a 5-second `staleTime` and installs `VueQueryPlugin`. On the server it stores `dehydrate(queryClient)` in `useState('vue-query')` on `app:rendered`, and on the client it calls `hydrate` with that state on `app:created`.
12β
13To run this example:
14β
15- `npm install`
16- `npm run dev`