diff --git a/docs/framework/preact/reference/functions/useQuery.md b/docs/framework/preact/reference/functions/useQuery.md index a73f2b19147..5afc02f1006 100644 --- a/docs/framework/preact/reference/functions/useQuery.md +++ b/docs/framework/preact/reference/functions/useQuery.md @@ -191,7 +191,7 @@ function Posts() { function useQuery(options: UseQueryOptions, queryClient?: QueryClient): UseQueryResult; ``` -Defined in: [packages/preact-query/src/useQuery.ts:282](https://github.com/TanStack/query/blob/main/packages/preact-query/src/useQuery.ts#L282) +Defined in: [packages/preact-query/src/useQuery.ts:286](https://github.com/TanStack/query/blob/main/packages/preact-query/src/useQuery.ts#L286) ### Type Parameters @@ -325,7 +325,9 @@ function Post({ postId }: { postId: number | undefined }) { } ``` -Seeding a detail query from an already-cached list, to skip the loading state: +Seeding a detail query from an already-cached list, to skip the loading state. `initialDataUpdatedAt` carries +over the list's own fetch time, so that if you set a `staleTime`, it's measured from when the list was +fetched rather than from now: ```tsx import { useQuery, useQueryClient } from '@tanstack/preact-query' @@ -339,6 +341,8 @@ function Post({ postId }: { postId: number }) { queryClient .getQueryData>(['posts']) ?.find((post) => post.id === postId), + initialDataUpdatedAt: () => + queryClient.getQueryState(['posts'])?.dataUpdatedAt, }) if (isError) return Error: {error.message} diff --git a/docs/framework/react/reference/functions/useQuery.md b/docs/framework/react/reference/functions/useQuery.md index c8fe48a009c..94a4b35d05d 100644 --- a/docs/framework/react/reference/functions/useQuery.md +++ b/docs/framework/react/reference/functions/useQuery.md @@ -193,7 +193,7 @@ function Posts() { function useQuery(options: UseQueryOptions, queryClient?: QueryClient): UseQueryResult; ``` -Defined in: [packages/react-query/src/useQuery.ts:282](https://github.com/TanStack/query/blob/main/packages/react-query/src/useQuery.ts#L282) +Defined in: [packages/react-query/src/useQuery.ts:286](https://github.com/TanStack/query/blob/main/packages/react-query/src/useQuery.ts#L286) ### Type Parameters @@ -327,7 +327,9 @@ function Post({ postId }: { postId: number | undefined }) { } ``` -Seeding a detail query from an already-cached list, to skip the loading state: +Seeding a detail query from an already-cached list, to skip the loading state. `initialDataUpdatedAt` carries +over the list's own fetch time, so that if you set a `staleTime`, it's measured from when the list was +fetched rather than from now: ```tsx import { useQuery, useQueryClient } from '@tanstack/react-query' @@ -341,6 +343,8 @@ function Post({ postId }: { postId: number }) { queryClient .getQueryData>(['posts']) ?.find((post) => post.id === postId), + initialDataUpdatedAt: () => + queryClient.getQueryState(['posts'])?.dataUpdatedAt, }) if (isError) return Error: {error.message} diff --git a/docs/framework/solid/reference/functions/useQuery.md b/docs/framework/solid/reference/functions/useQuery.md index 574b137a547..54b8c202c5e 100644 --- a/docs/framework/solid/reference/functions/useQuery.md +++ b/docs/framework/solid/reference/functions/useQuery.md @@ -11,7 +11,7 @@ redirect_from: function useQuery(options: UndefinedInitialDataOptions, queryClient?: () => QueryClient): UseQueryResult; ``` -Defined in: [packages/solid-query/src/useQuery.ts:181](https://github.com/TanStack/query/blob/main/packages/solid-query/src/useQuery.ts#L181) +Defined in: [packages/solid-query/src/useQuery.ts:185](https://github.com/TanStack/query/blob/main/packages/solid-query/src/useQuery.ts#L185) Subscribes to a query: a declarative dependency on an asynchronous source of data that is tied to a unique key. The query runs when the options call for it — `enabled: false` skips the initial fetch. @@ -159,7 +159,9 @@ function Post(props: { postId: number | undefined }) { } ``` -Seeding a detail query from an already-cached list, to skip the loading state: +Seeding a detail query from an already-cached list, to skip the loading state. `initialDataUpdatedAt` carries +over the list's own fetch time, so that if you set a `staleTime`, it's measured from when the list was +fetched rather than from now: ```tsx import { useQuery, useQueryClient } from '@tanstack/solid-query' @@ -173,6 +175,8 @@ function Post(props: { postId: number }) { queryClient .getQueryData>(['posts']) ?.find((post) => post.id === props.postId), + initialDataUpdatedAt: () => + queryClient.getQueryState(['posts'])?.dataUpdatedAt, })) return postQuery.isError ? Error: {postQuery.error.message} :

{postQuery.data?.title}

@@ -215,7 +219,7 @@ function Posts() { function useQuery(options: DefinedInitialDataOptions, queryClient?: () => QueryClient): DefinedUseQueryResult; ``` -Defined in: [packages/solid-query/src/useQuery.ts:233](https://github.com/TanStack/query/blob/main/packages/solid-query/src/useQuery.ts#L233) +Defined in: [packages/solid-query/src/useQuery.ts:237](https://github.com/TanStack/query/blob/main/packages/solid-query/src/useQuery.ts#L237) Subscribes to a query: a declarative dependency on an asynchronous source of data that is tied to a unique key. The query runs when the options call for it — `enabled: false` skips the initial fetch. diff --git a/docs/framework/solid/reference/variables/createQuery.md b/docs/framework/solid/reference/variables/createQuery.md index 1f53bb2be7f..1d6e2be2b1b 100644 --- a/docs/framework/solid/reference/variables/createQuery.md +++ b/docs/framework/solid/reference/variables/createQuery.md @@ -164,7 +164,9 @@ function Post(props: { postId: number | undefined }) { } ``` -Seeding a detail query from an already-cached list, to skip the loading state: +Seeding a detail query from an already-cached list, to skip the loading state. `initialDataUpdatedAt` carries +over the list's own fetch time, so that if you set a `staleTime`, it's measured from when the list was +fetched rather than from now: ```tsx import { useQuery, useQueryClient } from '@tanstack/solid-query' @@ -178,6 +180,8 @@ function Post(props: { postId: number }) { queryClient .getQueryData>(['posts']) ?.find((post) => post.id === props.postId), + initialDataUpdatedAt: () => + queryClient.getQueryState(['posts'])?.dataUpdatedAt, })) return postQuery.isError ? Error: {postQuery.error.message} :

{postQuery.data?.title}

diff --git a/docs/framework/vue/reference/functions/useQuery.md b/docs/framework/vue/reference/functions/useQuery.md index fd930e8de0a..5441786b1dc 100644 --- a/docs/framework/vue/reference/functions/useQuery.md +++ b/docs/framework/vue/reference/functions/useQuery.md @@ -90,7 +90,7 @@ const { data, isError, error } = useQuery({ function useQuery(options: UndefinedInitialQueryOptions, queryClient?: QueryClient): UseQueryReturnType; ``` -Defined in: [packages/vue-query/src/useQuery.ts:208](https://github.com/TanStack/query/blob/main/packages/vue-query/src/useQuery.ts#L208) +Defined in: [packages/vue-query/src/useQuery.ts:212](https://github.com/TanStack/query/blob/main/packages/vue-query/src/useQuery.ts#L212) `enabled` tracks reactive dependencies automatically as a `ref`, a plain value, or a reactive getter (`() => ...`). `queryKey` reacts through a `ref` or a reactive getter for the array itself, or `ref`s and @@ -203,7 +203,9 @@ const { data, isLoading, isError, error } = useQuery({ ``` -Seeding a detail query from an already-cached list, to skip the loading state: +Seeding a detail query from an already-cached list, to skip the loading state. `initialDataUpdatedAt` carries +over the list's own fetch time, so that if you set a `staleTime`, it's measured from when the list was +fetched rather than from now: ```vue @@ -259,7 +263,7 @@ const { data, isPlaceholderData, isError, error } = useQuery({ function useQuery(options: MaybeRefOrGetter>, queryClient?: QueryClient): UseQueryReturnType; ``` -Defined in: [packages/vue-query/src/useQuery.ts:284](https://github.com/TanStack/query/blob/main/packages/vue-query/src/useQuery.ts#L284) +Defined in: [packages/vue-query/src/useQuery.ts:288](https://github.com/TanStack/query/blob/main/packages/vue-query/src/useQuery.ts#L288) Fallback overload for options whose `initialData` presence isn't statically known — for example, a `ref`/reactive object built up conditionally, rather than a plain object literal. Prefer one of the other diff --git a/packages/preact-query/src/useQuery.ts b/packages/preact-query/src/useQuery.ts index bfbadf2221f..5b96b6d9d24 100644 --- a/packages/preact-query/src/useQuery.ts +++ b/packages/preact-query/src/useQuery.ts @@ -224,7 +224,9 @@ export function useQuery< * ``` * * @example - * Seeding a detail query from an already-cached list, to skip the loading state: + * Seeding a detail query from an already-cached list, to skip the loading state. `initialDataUpdatedAt` carries + * over the list's own fetch time, so that if you set a `staleTime`, it's measured from when the list was + * fetched rather than from now: * ```tsx * import { useQuery, useQueryClient } from '@tanstack/preact-query' * @@ -238,6 +240,8 @@ export function useQuery< * queryClient * .getQueryData>(['posts']) * ?.find((post) => post.id === postId), + * initialDataUpdatedAt: () => + * queryClient.getQueryState(['posts'])?.dataUpdatedAt, * }) * * if (isError) return Error: {error.message} diff --git a/packages/react-query/src/useQuery.ts b/packages/react-query/src/useQuery.ts index d14c6497bbf..b2fee39a67b 100644 --- a/packages/react-query/src/useQuery.ts +++ b/packages/react-query/src/useQuery.ts @@ -224,7 +224,9 @@ export function useQuery< * ``` * * @example - * Seeding a detail query from an already-cached list, to skip the loading state: + * Seeding a detail query from an already-cached list, to skip the loading state. `initialDataUpdatedAt` carries + * over the list's own fetch time, so that if you set a `staleTime`, it's measured from when the list was + * fetched rather than from now: * ```tsx * import { useQuery, useQueryClient } from '@tanstack/react-query' * @@ -238,6 +240,8 @@ export function useQuery< * queryClient * .getQueryData>(['posts']) * ?.find((post) => post.id === postId), + * initialDataUpdatedAt: () => + * queryClient.getQueryState(['posts'])?.dataUpdatedAt, * }) * * if (isError) return Error: {error.message} diff --git a/packages/solid-query/src/useQuery.ts b/packages/solid-query/src/useQuery.ts index 2b098827bdc..536b9160a33 100644 --- a/packages/solid-query/src/useQuery.ts +++ b/packages/solid-query/src/useQuery.ts @@ -127,7 +127,9 @@ import type { * ``` * * @example - * Seeding a detail query from an already-cached list, to skip the loading state: + * Seeding a detail query from an already-cached list, to skip the loading state. `initialDataUpdatedAt` carries + * over the list's own fetch time, so that if you set a `staleTime`, it's measured from when the list was + * fetched rather than from now: * ```tsx * import { useQuery, useQueryClient } from '@tanstack/solid-query' * @@ -141,6 +143,8 @@ import type { * queryClient * .getQueryData>(['posts']) * ?.find((post) => post.id === props.postId), + * initialDataUpdatedAt: () => + * queryClient.getQueryState(['posts'])?.dataUpdatedAt, * })) * * return postQuery.isError ? Error: {postQuery.error.message} :

{postQuery.data?.title}

diff --git a/packages/vue-query/src/useQuery.ts b/packages/vue-query/src/useQuery.ts index 57286fb4a16..d3a1b002667 100644 --- a/packages/vue-query/src/useQuery.ts +++ b/packages/vue-query/src/useQuery.ts @@ -154,7 +154,9 @@ export function useQuery< * ``` * * @example - * Seeding a detail query from an already-cached list, to skip the loading state: + * Seeding a detail query from an already-cached list, to skip the loading state. `initialDataUpdatedAt` carries + * over the list's own fetch time, so that if you set a `staleTime`, it's measured from when the list was + * fetched rather than from now: * ```vue * *