mirror of
https://github.com/TanStack/query.git
synced 2026-11-18 19:33:22 +00:00
* docs(examples): describe each example in its README with a summary, the framework it is built with, how it works and the npm commands * docs(examples): add the framework or router to the README heading and page title of examples that have variants * docs(examples/react): rename the Next.js examples to '<feature>-nextjs-<pages|app>-router' * docs(examples/react): update package names, docs links and labels, and the lockfile for the renamed Next.js examples * docs(examples): rename 'svelte/sveltekit', 'solid/solid-start-streaming' and 'angular/router' to '<feature>-<framework>' * docs(examples): correct README details on staleness, hydration, 'hasMore', streaming and dependent queries, and prefetch on 'focusin' in 'vue/prefetching-nuxt4' |
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