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

README.md

15 lines964 Bytes

1# TanStack Vue Query Batching Example
2​
3Several components request characters at the same time, and an async batcher from TanStack Pacer combines those requests into one.
4​
5## How it works
6​
7- `src/services/characters/api.ts` queues each `getCharacter(id)` call in an `AsyncBatcher` from `@tanstack/vue-pacer` with `wait: 0`, so calls made together become one Rick and Morty API request. Each caller gets its own character, or `null` if it was not found.
8- `src/services/characters/queries.ts` defines `charactersQueries.detail(id)`, a `queryOptions` factory keyed by `['characters', 'detail', id]` with a 1-minute `staleTime`.
9- `src/CharacterList.vue` passes a getter to `useQueries` that maps the `ids` prop to `charactersQueries.detail(id)`, so all character queries start in the same tick and the batcher combines them.
10- `src/main.ts` installs `VueQueryPlugin` with `retry: 0` as the default query option.
11​
12To run this example:
13​
14- `npm install`
15- `npm run dev`