Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 6 additions & 2 deletions docs/framework/preact/reference/functions/useQuery.md
Original file line number Diff line number Diff line change
Expand Up @@ -191,7 +191,7 @@ function Posts() {
function useQuery<TQueryFnData, TError, TData, TQueryKey>(options: UseQueryOptions<TQueryFnData, TError, TData, TQueryKey>, queryClient?: QueryClient): UseQueryResult<TData, TError>;
```

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

Expand Down Expand Up @@ -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'

Expand All @@ -339,6 +341,8 @@ function Post({ postId }: { postId: number }) {
queryClient
.getQueryData<Array<Post>>(['posts'])
?.find((post) => post.id === postId),
initialDataUpdatedAt: () =>
queryClient.getQueryState(['posts'])?.dataUpdatedAt,
})

if (isError) return <span>Error: {error.message}</span>
Expand Down
8 changes: 6 additions & 2 deletions docs/framework/react/reference/functions/useQuery.md
Original file line number Diff line number Diff line change
Expand Up @@ -193,7 +193,7 @@ function Posts() {
function useQuery<TQueryFnData, TError, TData, TQueryKey>(options: UseQueryOptions<TQueryFnData, TError, TData, TQueryKey>, queryClient?: QueryClient): UseQueryResult<TData, TError>;
```

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

Expand Down Expand Up @@ -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'

Expand All @@ -341,6 +343,8 @@ function Post({ postId }: { postId: number }) {
queryClient
.getQueryData<Array<Post>>(['posts'])
?.find((post) => post.id === postId),
initialDataUpdatedAt: () =>
queryClient.getQueryState(['posts'])?.dataUpdatedAt,
})

if (isError) return <span>Error: {error.message}</span>
Expand Down
10 changes: 7 additions & 3 deletions docs/framework/solid/reference/functions/useQuery.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ redirect_from:
function useQuery<TQueryFnData, TError, TData, TQueryKey>(options: UndefinedInitialDataOptions<TQueryFnData, TError, TData, TQueryKey>, queryClient?: () => QueryClient): UseQueryResult<TData, TError>;
```

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.
Expand Down Expand Up @@ -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'

Expand All @@ -173,6 +175,8 @@ function Post(props: { postId: number }) {
queryClient
.getQueryData<Array<Post>>(['posts'])
?.find((post) => post.id === props.postId),
initialDataUpdatedAt: () =>
queryClient.getQueryState(['posts'])?.dataUpdatedAt,
}))

return postQuery.isError ? <span>Error: {postQuery.error.message}</span> : <h1>{postQuery.data?.title}</h1>
Expand Down Expand Up @@ -215,7 +219,7 @@ function Posts() {
function useQuery<TQueryFnData, TError, TData, TQueryKey>(options: DefinedInitialDataOptions<TQueryFnData, TError, TData, TQueryKey>, queryClient?: () => QueryClient): DefinedUseQueryResult<TData, TError>;
```

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.
Expand Down
6 changes: 5 additions & 1 deletion docs/framework/solid/reference/variables/createQuery.md
Original file line number Diff line number Diff line change
Expand Up @@ -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'

Expand All @@ -178,6 +180,8 @@ function Post(props: { postId: number }) {
queryClient
.getQueryData<Array<Post>>(['posts'])
?.find((post) => post.id === props.postId),
initialDataUpdatedAt: () =>
queryClient.getQueryState(['posts'])?.dataUpdatedAt,
}))

return postQuery.isError ? <span>Error: {postQuery.error.message}</span> : <h1>{postQuery.data?.title}</h1>
Expand Down
10 changes: 7 additions & 3 deletions docs/framework/vue/reference/functions/useQuery.md
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ const { data, isError, error } = useQuery({
function useQuery<TQueryFnData, TError, TData, TQueryKey>(options: UndefinedInitialQueryOptions<TQueryFnData, TError, TData, TQueryKey>, queryClient?: QueryClient): UseQueryReturnType<TData, TError>;
```

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
Expand Down Expand Up @@ -203,7 +203,9 @@ const { data, isLoading, isError, error } = useQuery({
</template>
```

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
<script setup lang="ts">
import { useQuery, useQueryClient } from '@tanstack/vue-query'
Expand All @@ -218,6 +220,8 @@ const { data, isError, error } = useQuery({
queryClient
.getQueryData<Array<Post>>(['posts'])
?.find((post) => post.id === props.postId),
initialDataUpdatedAt: () =>
queryClient.getQueryState(['posts'])?.dataUpdatedAt,
})
</script>

Expand Down Expand Up @@ -259,7 +263,7 @@ const { data, isPlaceholderData, isError, error } = useQuery({
function useQuery<TQueryFnData, TError, TData, TQueryKey>(options: MaybeRefOrGetter<UseQueryOptions<TQueryFnData, TError, TData, TQueryFnData, TQueryKey>>, queryClient?: QueryClient): UseQueryReturnType<TData, TError>;
```

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
Expand Down
6 changes: 5 additions & 1 deletion packages/preact-query/src/useQuery.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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'
*
Expand All @@ -238,6 +240,8 @@ export function useQuery<
* queryClient
* .getQueryData<Array<Post>>(['posts'])
* ?.find((post) => post.id === postId),
* initialDataUpdatedAt: () =>
* queryClient.getQueryState(['posts'])?.dataUpdatedAt,
* })
*
* if (isError) return <span>Error: {error.message}</span>
Expand Down
6 changes: 5 additions & 1 deletion packages/react-query/src/useQuery.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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'
*
Expand All @@ -238,6 +240,8 @@ export function useQuery<
* queryClient
* .getQueryData<Array<Post>>(['posts'])
* ?.find((post) => post.id === postId),
* initialDataUpdatedAt: () =>
* queryClient.getQueryState(['posts'])?.dataUpdatedAt,
* })
*
* if (isError) return <span>Error: {error.message}</span>
Expand Down
6 changes: 5 additions & 1 deletion packages/solid-query/src/useQuery.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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'
*
Expand All @@ -141,6 +143,8 @@ import type {
* queryClient
* .getQueryData<Array<Post>>(['posts'])
* ?.find((post) => post.id === props.postId),
* initialDataUpdatedAt: () =>
* queryClient.getQueryState(['posts'])?.dataUpdatedAt,
* }))
*
* return postQuery.isError ? <span>Error: {postQuery.error.message}</span> : <h1>{postQuery.data?.title}</h1>
Expand Down
6 changes: 5 additions & 1 deletion packages/vue-query/src/useQuery.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
* <script setup lang="ts">
* import { useQuery, useQueryClient } from '@tanstack/vue-query'
Expand All @@ -169,6 +171,8 @@ export function useQuery<
* queryClient
* .getQueryData<Array<Post>>(['posts'])
* ?.find((post) => post.id === props.postId),
* initialDataUpdatedAt: () =>
* queryClient.getQueryState(['posts'])?.dataUpdatedAt,
* })
* </script>
*
Expand Down
Loading