Skip to main content
Parallel queries allow you to fetch multiple pieces of data simultaneously, improving application performance by running requests concurrently rather than sequentially.

Multiple useQuery Hooks

The simplest way to run queries in parallel is to call useQuery 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, use useQueries:
useQueries is perfect for fetching data for a dynamic list of items, such as loading details for multiple user IDs, product SKUs, or other entities.

Combining Results

Use the combine 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 with useQueries:

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:
Use different staleTime values for queries with different freshness requirements. Static reference data can have a longer staleTime than frequently changing data.

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.
Avoid making queries dependent on each other when they could run in parallel. This reduces performance and increases total loading time.

QueriesObserver API

For advanced use cases outside of React, use QueriesObserver directly:
The QueriesObserver class is the underlying implementation that powers useQueries. It’s useful for non-React environments or advanced custom hooks.