Multiple useQuery Hooks
The simplest way to run queries in parallel is to calluseQuery multiple times:
When using multiple
useQuery hooks, TanStack Query automatically runs them in parallel. The browser’s connection limits determine how many can run simultaneously.useQueries Hook
For dynamic numbers of queries or better control, useuseQueries:
Combining Results
Use thecombine option to transform multiple query results into a single value:
1
Define queries array
Create an array of query configurations with their keys and fetch functions.
2
Add combine function
Transform the array of results into your desired data structure.
3
Use combined result
Access the transformed data and derived state from the combined result.
Type-Safe Queries
Define types for better TypeScript support withuseQueries:
Handling Individual Errors
Process errors from parallel queries independently:Each query in
useQueries maintains its own state, allowing you to handle loading, error, and success states independently.Dynamic Parallel Queries
Generate queries dynamically based on runtime data:Optimizing Parallel Queries
Shared Configuration
Apply common options to all queries:Selective Refetching
Refetch specific queries based on conditions:Waiting for All Queries
Wait for all queries to complete before showing content:Parallel Queries with Dependencies
Some queries may depend on others. See the Dependent Queries guide for handling sequential dependencies.QueriesObserver API
For advanced use cases outside of React, useQueriesObserver directly:
The
QueriesObserver class is the underlying implementation that powers useQueries. It’s useful for non-React environments or advanced custom hooks.