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

Method getQueryState

packages/query-core/src/queryClient.ts:352–365  ·  view source on GitHub ↗

* Imperative (non-reactive) way to retrieve an existing query's state. If the query does not * exist, `undefined` is returned. * * @example * ```ts * const state = queryClient.getQueryState(['posts']) * console.log(state?.dataUpdatedAt) * ```

(
    queryKey: TTaggedQueryKey,
  )

Source from the content-addressed store, hash-verified

350 * ```
351 */
352 getQueryState<
353 TQueryFnData = unknown,
354 TError = DefaultError,
355 TTaggedQueryKey extends QueryKey = QueryKey,
356 TInferredQueryFnData = InferDataFromTag<TQueryFnData, TTaggedQueryKey>,
357 TInferredError = InferErrorFromTag<TError, TTaggedQueryKey>,
358 >(
359 queryKey: TTaggedQueryKey,
360 ): QueryState<TInferredQueryFnData, TInferredError> | undefined {
361 const options = this.defaultQueryOptions({ queryKey })
362 return this.#queryCache.get<TInferredQueryFnData, TInferredError>(
363 options.queryHash,
364 )?.state
365 }
366
367 /**
368 * Removes queries from the cache that match the given filters. Unlike

Callers 15

ExamplesFunction · 0.45
ExamplesFunction · 0.45
ExamplesFunction · 0.45
ExamplesFunction · 0.45
ExamplesFunction · 0.45
ExamplesFunction · 0.45
Devtools.test.tsxFile · 0.45
utils.test-d.tsxFile · 0.45

Calls 2

defaultQueryOptionsMethod · 0.95
getMethod · 0.80

Tested by

no test coverage detected