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

Method getQueryData

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

* Imperative (non-reactive) way to retrieve data for a QueryKey. * Should only be used in callbacks or functions where reading the latest data is necessary, e.g. for optimistic updates. * * Hint: Do not use this function inside a component, because it won't receive updates. * Use `useQue

(queryKey: TTaggedQueryKey)

Source from the content-addressed store, hash-verified

186 * @see {@link QueryClient#getQueriesData}
187 */
188 getQueryData<
189 TQueryFnData = unknown,
190 TTaggedQueryKey extends QueryKey = QueryKey,
191 TInferredQueryFnData = InferDataFromTag<TQueryFnData, TTaggedQueryKey>,
192 >(queryKey: TTaggedQueryKey): TInferredQueryFnData | undefined {
193 const options = this.defaultQueryOptions({ queryKey })
194
195 return this.#queryCache.get<TInferredQueryFnData>(options.queryHash)?.state
196 .data
197 }
198
199 /**
200 * Returns the cached data of a query, or fetches it if there is none. With `revalidateIfStale`,

Callers 15

ExamplesFunction · 0.45
ExamplesFunction · 0.45
ExamplesFunction · 0.45
ExamplesFunction · 0.45
ExamplesFunction · 0.45
ExamplesFunction · 0.45
Explorer.test.tsxFile · 0.45
Devtools.test.tsxFile · 0.45
persist.test.tsFile · 0.45
streamedQueryFunction · 0.45

Calls 2

defaultQueryOptionsMethod · 0.95
getMethod · 0.80

Tested by

no test coverage detected