useQueries
TheuseQueries hook allows you to fetch multiple queries in parallel. It accepts an array of query options objects and returns an array of query results.
Import
Signature
Type Parameters
type
Array type containing the configuration for each query
type
default:"QueriesResults<T>"
The type of the combined result after the
combine function is appliedParameters
object
required
readonly [...QueriesOptions<T>]
required
An array of query option objects. Each query option object accepts most
useQuery options except:placeholderDatacannot be a functionsubscribedis not available per query (use the top-levelsubscribedinstead)
queryKey(required): Unique key for the queryqueryFn: Function that fetches the dataenabled: Whether the query should runstaleTime: Time in ms after data is considered stalegcTime: Time in ms for garbage collectionselect: Transform function for the data- All other standard
useQueryoptions
(result: QueriesResults<T>) => TCombinedResult
Optional function to combine or transform the array of query results into a different shape
boolean
default:"true"
Set this to
false to unsubscribe all queries from updates to the query cacheQueryClient
Optional QueryClient instance to use. If not provided, the client from the nearest
QueryClientProvider will be used.Returns
Returns an array of query results, where each result has the same shape as the result fromuseQuery:
combine function is provided, returns the result of that function instead.
Type Inference
TheuseQueries hook provides excellent type inference:
Examples
Basic Usage
With Type Safety
Dynamic Queries
With Combine Function
Conditional Queries
Dependent Queries
With Error Handling
With Type Inference from Query Options
Important Notes
- The queries are executed in parallel
- Each query maintains its own cache entry
- The
combinefunction is called on every render, so keep it lightweight or memoize expensive computations - Unlike
useQuery, you cannot useplaceholderDataas a function inuseQueries - The order of results matches the order of queries in the input array
- Supports Suspense and Error Boundaries when individual queries have those options enabled