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

README.md

14 lines852 Bytes

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`