MCPcopy
hub / github.com/TanStack/query / useQueries

Function useQueries

packages/react-query/src/useQueries.ts:208–332  ·  view source on GitHub ↗
(
  {
    queries,
    ...options
  }: {
    queries:
      | readonly [...QueriesOptions<T>]
      | readonly [...{ [K in keyof T]: GetUseQueryOptionsForUseQueries<T[K]> }]
    combine?: (result: QueriesResults<T>) => TCombinedResult
    subscribed?: boolean
  },
  queryClient?: QueryClient,
)

Source from the content-addressed store, hash-verified

206 : { [K in keyof T]: GetUseQueryResult<T[K]> }
207
208export function useQueries<
209 T extends Array<any>,
210 TCombinedResult = QueriesResults<T>,
211>(
212 {
213 queries,
214 ...options
215 }: {
216 queries:
217 | readonly [...QueriesOptions<T>]
218 | readonly [...{ [K in keyof T]: GetUseQueryOptionsForUseQueries<T[K]> }]
219 combine?: (result: QueriesResults<T>) => TCombinedResult
220 subscribed?: boolean
221 },
222 queryClient?: QueryClient,
223): TCombinedResult {
224 const client = useQueryClient(queryClient)
225 const isRestoring = useIsRestoring()
226 const errorResetBoundary = useQueryErrorResetBoundary()
227
228 const defaultedQueries = React.useMemo(
229 () =>
230 queries.map((opts) => {
231 const defaultedOptions = client.defaultQueryOptions(
232 opts as QueryObserverOptions,
233 )
234
235 // Make sure the results are already in fetching state before subscribing or updating options
236 defaultedOptions._optimisticResults = isRestoring
237 ? 'isRestoring'
238 : 'optimistic'
239
240 return defaultedOptions
241 }),
242 [queries, client, isRestoring],
243 )
244
245 defaultedQueries.forEach((query) => {
246 ensureSuspenseTimers(query)
247 ensurePreventErrorBoundaryRetry(query, errorResetBoundary)
248 })
249
250 useClearResetErrorBoundary(errorResetBoundary)
251
252 const [observer] = React.useState(
253 () =>
254 new QueriesObserver<TCombinedResult>(
255 client,
256 defaultedQueries,
257 options as QueriesObserverOptions<TCombinedResult>,
258 ),
259 )
260
261 // note: this must be called before useSyncExternalStore
262 const [optimisticResult, getCombinedResult, trackResult] =
263 observer.getOptimisticResult(
264 defaultedQueries,
265 (options as QueriesObserverOptions<TCombinedResult>).combine,

Callers 15

Example2Function · 0.90
Example3Function · 0.90
Example4Function · 0.90
Example5Function · 0.90
Example2Function · 0.90
Example3Function · 0.90
Example4Function · 0.90
Example5Function · 0.90
ExamplesFunction · 0.90
ExamplesFunction · 0.90
ExamplesFunction · 0.90
ExamplesFunction · 0.90

Calls 15

useQueryClientFunction · 0.90
useIsRestoringFunction · 0.90
ensureSuspenseTimersFunction · 0.90
shouldSuspendFunction · 0.90
fetchOptimisticFunction · 0.90
willFetchFunction · 0.90
getHasErrorFunction · 0.90
defaultQueryOptionsMethod · 0.80
setQueriesMethod · 0.80

Tested by 6

useCustomQueriesFunction · 0.72
TestComponentFunction · 0.72
PageFunction · 0.72
PageFunction · 0.40
useWrappedQueriesFunction · 0.40
PageFunction · 0.40

Used in the wild real call sites across dependent graphs

searching dependent graphs…