Skip to content
Source
Sign inSign up
TanStack/query
Open History to see the last commit

README.md

14 lines852 Bytes

TanStack Solid 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.ts defines charactersQueries.detail(id) with queryOptions, keyed by ['characters', 'detail', id] with a 1-minute staleTime.
  • src/services/characters/api.ts adds each getCharacter(id) call to an AsyncBatcher from TanStack Pacer with wait: 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/index.tsx passes one charactersQueries.detail(id) per id to useQueries, so each character is still a separate query in the cache even though the network request is shared.

To run this example:

  • npm install
  • npm run dev