Open History to see the last commit
TanStack Vue 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/api.tsqueues eachgetCharacter(id)call in anAsyncBatcherfrom@tanstack/vue-pacerwithwait: 0, so calls made together become one Rick and Morty API request. Each caller gets its own character, ornullif it was not found.src/services/characters/queries.tsdefinescharactersQueries.detail(id), aqueryOptionsfactory keyed by['characters', 'detail', id]with a 1-minutestaleTime.src/CharacterList.vuepasses a getter touseQueriesthat maps theidsprop tocharactersQueries.detail(id), so all character queries start in the same tick and the batcher combines them.src/main.tsinstallsVueQueryPluginwithretry: 0as the default query option.
To run this example:
npm installnpm run dev