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

Method getQueryState

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

* Imperative (non-reactive) way to retrieve an existing query's state. If the query does not * exist, `undefined` is returned. * @param queryKey - The query key of the query to read. * @returns The query's state, or `undefined` if no query with this key exists. * @example * ```ts *

(
    queryKey: TTaggedQueryKey,
  )

Source from the content-addressed store, hash-verified

369 * ```
370 */
371 getQueryState<
372 TQueryFnData = unknown,
373 TError = DefaultError,
374 TTaggedQueryKey extends QueryKey = QueryKey,
375 TInferredQueryFnData = InferDataFromTag<TQueryFnData, TTaggedQueryKey>,
376 TInferredError = InferErrorFromTag<TError, TTaggedQueryKey>,
377 >(
378 queryKey: TTaggedQueryKey,
379 ): QueryState<TInferredQueryFnData, TInferredError> | undefined {
380 const options = this.defaultQueryOptions({ queryKey })
381 return this.#queryCache.get<TInferredQueryFnData, TInferredError>(
382 options.queryHash,
383 )?.state
384 }
385
386 /**
387 * 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