Skip to content
Source
Sign inSign up
TanStack/query
Open History to see the last commit

README.md

16 lines872 Bytes

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`