examples/svelte/batching
| Name | Last commit message | Last commit date |
|---|---|---|
| .. | ||
README.md
TanStack Svelte 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/lib/services/characters/queries.tsdefinescharactersQueries.detail(id)withqueryOptions, keyed by['characters', 'detail', id]with a 1-minutestaleTime.src/lib/services/characters/api.tsadds eachgetCharacter(id)call to anAsyncBatcherfrom TanStack Pacer withwait: 0. The batcher sends one Rick and Morty API request for all collected ids and resolves each query's promise with its own character.src/lib/Characters.sveltepasses onecharactersQueries.detail(id)per id tocreateQueries, so each character is still a separate query in the cache even though the network request is shared.src/App.svelteparses the comma-separated ids and passes them toCharacterswhen "Load characters" is clicked.
To run this example:
npm installnpm run dev