Skip to main content

useQueries

The useQueries 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 applied

Parameters

object
required
readonly [...QueriesOptions<T>]
required
An array of query option objects. Each query option object accepts most useQuery options except:
  • placeholderData cannot be a function
  • subscribed is not available per query (use the top-level subscribed instead)
Each query can have:
  • queryKey (required): Unique key for the query
  • queryFn: Function that fetches the data
  • enabled: Whether the query should run
  • staleTime: Time in ms after data is considered stale
  • gcTime: Time in ms for garbage collection
  • select: Transform function for the data
  • All other standard useQuery options
(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 cache
QueryClient
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 from useQuery:
If a combine function is provided, returns the result of that function instead.

Type Inference

The useQueries 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 combine function is called on every render, so keep it lightweight or memoize expensive computations
  • Unlike useQuery, you cannot use placeholderData as a function in useQueries
  • 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

Source

Implementation: useQueries.ts:207