| 301 | * ``` |
| 302 | */ |
| 303 | export function useQueries< |
| 304 | T extends Array<any>, |
| 305 | TCombinedResult = QueriesResults<T>, |
| 306 | >( |
| 307 | { |
| 308 | queries, |
| 309 | ...options |
| 310 | }: { |
| 311 | /** |
| 312 | * An array with query option objects, mostly identical to `useQuery` — except that `queryClient` and |
| 313 | * `subscribed` aren't accepted per-query (`subscribed` is a top-level option here instead), and |
| 314 | * `placeholderData` accepts a {@link QueriesPlaceholderDataFunction}, which is called with `previousData` |
| 315 | * and `previousQuery` always `undefined`, rather than `useQuery`'s placeholder function. |
| 316 | */ |
| 317 | queries: |
| 318 | | readonly [...QueriesOptions<T>] |
| 319 | | readonly [...{ [K in keyof T]: GetUseQueryOptionsForUseQueries<T[K]> }] |
| 320 | /** |
| 321 | * Use this to combine the results of the queries into a single value. The result will be structurally |
| 322 | * shared to be as referentially stable as possible. |
| 323 | */ |
| 324 | combine?: (result: QueriesResults<T>) => TCombinedResult |
| 325 | /** |
| 326 | * Set this to `false` to unsubscribe this observer from updates to the query cache. |
| 327 | * @defaultValue true |
| 328 | */ |
| 329 | subscribed?: boolean |
| 330 | }, |
| 331 | queryClient?: QueryClient, |
| 332 | ): TCombinedResult { |
| 333 | const client = useQueryClient(queryClient) |
| 334 | const isRestoring = useIsRestoring() |
| 335 | const errorResetBoundary = useQueryErrorResetBoundary() |
| 336 | const subscribed = options.subscribed !== false |
| 337 | |
| 338 | const defaultedQueries = useMemo( |
| 339 | () => |
| 340 | queries.map((opts) => { |
| 341 | const defaultedOptions = client.defaultQueryOptions( |
| 342 | opts as QueryObserverOptions, |
| 343 | ) |
| 344 | |
| 345 | // Make sure the results are already in fetching state before subscribing or updating options |
| 346 | defaultedOptions._optimisticResults = isRestoring |
| 347 | ? 'isRestoring' |
| 348 | : subscribed |
| 349 | ? 'optimistic' |
| 350 | : undefined |
| 351 | |
| 352 | return defaultedOptions |
| 353 | }), |
| 354 | [queries, client, isRestoring, subscribed], |
| 355 | ) |
| 356 | |
| 357 | defaultedQueries.forEach((queryOptions) => { |
| 358 | ensureSuspenseTimers(queryOptions) |
| 359 | const query = client.getQueryCache().get(queryOptions.queryHash) |
| 360 | ensurePreventErrorBoundaryRetry(queryOptions, errorResetBoundary, query) |