examples/lit/batching
| Name | Last commit message | Last commit date |
|---|---|---|
| .. | ||
README.md
TanStack Lit 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), aqueryOptionsfactory keyed by['characters', 'detail', id]with a 1-minutestaleTime.src/services/characters/api.tsdoes not fetch ingetCharacter. Instead, it adds the id to anAsyncBatcherfrom@tanstack/lit-pacerwithwait: 0, which sends one request to the Rick and Morty API for all ids queued in the same tick and resolves each query's promise with its character.src/character-list.tscallscreateQueriesControllerwith onecharactersQueries.detail(id)per entered id, so each id still has its own cache entry and status.
To run this example:
npm installnpm run dev