mirror of
https://github.com/TanStack/query.git
synced 2026-11-16 22:50:20 +00:00
* chore(*): adopt '@tanstack/oxlint-config' and '@tanstack/oxfmt-config', and fix the newly reported lint errors * chore(pnpm-lock.yaml): run 'pnpm dedupe' * chore(scripts): move 'oxlint/plugin.ts' to 'oxlint-plugin.ts' to match the flat layout of 'scripts' * chore(pnpm-workspace.yaml): update '@typescript-eslint/parser' and '@typescript-eslint/rule-tester' to '^8.72.1' to match the deduped '@typescript-eslint/utils' |
History
|
|
|---|---|---|
| .. | ||
| public | ||
| src | ||
| .gitignore | ||
| eslint.config.js | ||
| index.html | ||
| package.json | ||
| README.md | ||
| tsconfig.json | ||
| vite.config.ts | ||
TanStack React Query Batching Example
Several components request characters at the same time, and an async batcher from TanStack Pacer combines those requests into one.
How it works
src/services/characters/queries.tsdefinescharactersQueries.detail(id)withqueryOptions, keyed by['characters', 'detail', id]with astaleTimeof 1 minute.src/services/characters/api.tshasgetCharacter(id)add a request to anAsyncBatcherfrom TanStack Pacer and return a deferred promise. Withwait: 0, the requests collected in the same tick are sent as one call to/api/character/[ids], and each promise resolves with its own character ornull.src/index.tsxpasses the entered ids touseQuerieswithids.map((id) => charactersQueries.detail(id)), so each id is its own query while the network sees a single request.
To run this example:
npm installnpm run dev