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

Method getQueryData

packages/query-core/src/queryClient.ts:191–200  ·  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

189 * @see {@link QueryClient#getQueriesData}
190 */
191 getQueryData<
192 TQueryFnData = unknown,
193 TTaggedQueryKey extends QueryKey = QueryKey,
194 TInferredQueryFnData = InferDataFromTag<TQueryFnData, TTaggedQueryKey>,
195 >(queryKey: TTaggedQueryKey): TInferredQueryFnData | undefined {
196 const options = this.defaultQueryOptions({ queryKey })
197
198 return this.#queryCache.get<TInferredQueryFnData>(options.queryHash)?.state
199 .data
200 }
201
202 /**
203 * 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