MCPcopy Create free account
hub / github.com/TanStack/query / useQueries

Function useQueries

packages/react-query/src/useQueries.ts:207–331  ·  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

205 : { [K in keyof T]: GetUseQueryResult<T[K]> }
206
207export function useQueries<
208 T extends Array<any>,
209 TCombinedResult = QueriesResults<T>,
210>(
211 {
212 queries,
213 ...options
214 }: {
215 queries:
216 | readonly [...QueriesOptions<T>]
217 | readonly [...{ [K in keyof T]: GetUseQueryOptionsForUseQueries<T[K]> }]
218 combine?: (result: QueriesResults<T>) => TCombinedResult
219 subscribed?: boolean
220 },
221 queryClient?: QueryClient,
222): TCombinedResult {
223 const client = useQueryClient(queryClient)
224 const isRestoring = useIsRestoring()
225 const errorResetBoundary = useQueryErrorResetBoundary()
226 const subscribed = options.subscribed !== false
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 : subscribed
239 ? 'optimistic'
240 : undefined
241
242 return defaultedOptions
243 }),
244 [queries, client, isRestoring, subscribed],
245 )
246
247 defaultedQueries.forEach((queryOptions) => {
248 ensureSuspenseTimers(queryOptions)
249 const query = client.getQueryCache().get(queryOptions.queryHash)
250 ensurePreventErrorBoundaryRetry(queryOptions, errorResetBoundary, query)
251 })
252
253 useClearResetErrorBoundary(errorResetBoundary)
254
255 const [observer] = React.useState(
256 () =>
257 new QueriesObserver<TCombinedResult>(
258 client,
259 defaultedQueries,
260 options as QueriesObserverOptions<TCombinedResult>,
261 ),
262 )
263
264 // note: this must be called before useSyncExternalStore

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
getHasErrorFunction · 0.90
defaultQueryOptionsMethod · 0.80
getMethod · 0.80
getQueryCacheMethod · 0.80

Tested by 8

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