From 3bd0dee96ec99080fdb2636442c61e19468af7d5 Mon Sep 17 00:00:00 2001 From: Tyler <26290074+tylersayshi@users.noreply.github.com> Date: Thu, 27 Mar 2025 09:20:44 -0700 Subject: [PATCH 1/3] docs(queryClient): JSDoc hint for queryClient.getQueryData follow up from: https://bsky.app/profile/tylur.dev/post/3llennpm4kk2z --- packages/query-core/src/queryClient.ts | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/packages/query-core/src/queryClient.ts b/packages/query-core/src/queryClient.ts index f9f15543dca..af5142332f4 100644 --- a/packages/query-core/src/queryClient.ts +++ b/packages/query-core/src/queryClient.ts @@ -119,6 +119,12 @@ export class QueryClient { return this.#mutationCache.findAll({ ...filters, status: 'pending' }).length } + /** + * Get the data for a query key. This is helpful when query data is needed to be gotten once (non-reactive). + * + * Hint: If you're using this inside a component and wondering why it does not update, you + * should use `useQuery` to get reactive data. + */ getQueryData< TQueryFnData = unknown, TTaggedQueryKey extends QueryKey = QueryKey, From e8c7d1c6a4fc45d45aab53f4b9981df0d4134172 Mon Sep 17 00:00:00 2001 From: Dominik Dorfmeister Date: Fri, 28 Mar 2025 17:24:03 +0100 Subject: [PATCH 2/3] Update packages/query-core/src/queryClient.ts --- packages/query-core/src/queryClient.ts | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/packages/query-core/src/queryClient.ts b/packages/query-core/src/queryClient.ts index af5142332f4..bcdaed684dc 100644 --- a/packages/query-core/src/queryClient.ts +++ b/packages/query-core/src/queryClient.ts @@ -120,10 +120,10 @@ export class QueryClient { } /** - * Get the data for a query key. This is helpful when query data is needed to be gotten once (non-reactive). + * 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: If you're using this inside a component and wondering why it does not update, you - * should use `useQuery` to get reactive data. + * Hint: Do not use this function inside a component, because it won't receive updates. + * Use `useQuery` to create a `QueryObserver` that subscribes to changes. */ getQueryData< TQueryFnData = unknown, From 502eaa099bea1c575bda188772f5dfdb0e739078 Mon Sep 17 00:00:00 2001 From: Dominik Dorfmeister Date: Fri, 28 Mar 2025 17:24:26 +0100 Subject: [PATCH 3/3] Update packages/query-core/src/queryClient.ts --- packages/query-core/src/queryClient.ts | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/packages/query-core/src/queryClient.ts b/packages/query-core/src/queryClient.ts index bcdaed684dc..b63d4fd004f 100644 --- a/packages/query-core/src/queryClient.ts +++ b/packages/query-core/src/queryClient.ts @@ -120,7 +120,8 @@ export class QueryClient { } /** - * 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. + * 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 `useQuery` to create a `QueryObserver` that subscribes to changes.