Open History to see the last commit
1# TanStack Solid 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/queries.ts` defines `charactersQueries.detail(id)` with `queryOptions`, keyed by `['characters', 'detail', id]` with a 1-minute `staleTime`.
8- `src/services/characters/api.ts` adds each `getCharacter(id)` call to an `AsyncBatcher` from TanStack Pacer with `wait: 0`. The batcher sends one Rick and Morty API request for all collected ids and resolves each query's promise with its own character.
9- `src/index.tsx` passes one `charactersQueries.detail(id)` per id to `useQueries`, so each character is still a separate query in the cache even though the network request is shared.
10β
11To run this example:
12β
13- `npm install`
14- `npm run dev`