Overview
TheQueriesObserver allows you to observe multiple queries at once and optionally combine their results. It’s the foundation for framework-specific hooks like useQueries in React.
Constructor
QueryClient
required
The QueryClient instance
Array<QueryObserverOptions>
required
Array of query options
QueriesObserverOptions<TCombinedResult>
Methods
subscribe()
Subscribes to updates from all queries.(results: Array<QueryObserverResult>) => void
required
Callback function that receives an array of query results
getCurrentResult()
Returns the current results from all queries without subscribing.setQueries()
Updates the queries being observed.Array<QueryObserverOptions>
required
New array of query options
QueriesObserverOptions<TCombinedResult>
New observer options
getQueries()
Returns the underlying Query instances.getObservers()
Returns the underlying QueryObserver instances.getOptimisticResult()
Returns optimistic results and a combine function.[rawResults, combineFunction, trackFunction]
destroy()
Destroys the observer and cleans up all query observers.Combining Results
You can provide acombine function to transform the array of results into any shape:
Type Parameters
TCombinedResult- The type of the combined result (defaults toArray<QueryObserverResult>)
Usage Example
Dynamic Queries
You can dynamically add or remove queries:Result Array Structure
The results array maintains the same order as the queries array:When using the
combine option, the combined result is memoized and only recomputed when the individual query results change.