useQueries hook allows you to fetch multiple queries in parallel with a dynamic number of queries. It’s useful when you need to fetch an array of queries where the length is not known at build time.
Import
Signature
Parameters
object
required
The queries options object.
QueryClient
Override the default QueryClient.
Query Options
Each query in thequeries array accepts the following options:
QueryKey
required
The unique key for the query.
QueryFunction<TQueryFnData, TQueryKey>
required
The function to fetch the data.
boolean
default:"true"
Set to
false to disable the query.number | 'static'
default:"0"
Time in milliseconds after data is considered stale.
number
default:"300000"
Garbage collection time in milliseconds.
boolean | number | ((failureCount: number, error: TError) => boolean)
default:"3"
Retry configuration.
(data: TQueryData) => TData
Transform or select part of the data.
All options available to
useQuery are also available for each query in the array, except placeholderData which has a slightly different signature.Returns
array
By default, returns an array of query results. Each element corresponds to a query in the input array.When using the
combine option, returns the result of the combine function.Examples
Basic Usage
With Type Safety
Using Combine
Dynamic Queries with Conditional Execution
Handling All States
With Select Transform
Combining with Other Data
Notes
The
queries array must be a stable reference (e.g., use useMemo if generating dynamically) or the hook will re-render infinitely.Use
useQueries when the number of queries is dynamic. If you have a fixed number of queries, use multiple useQuery calls instead.Each query in the array is tracked independently, so you can have different loading states, errors, and data for each query.
The
combine option is useful for deriving computed values from multiple queries or reducing the number of re-renders.