diff --git a/docs/framework/vue/reference/functions/useQuery.md b/docs/framework/vue/reference/functions/useQuery.md index 315e7097f5f..4cab6877e9e 100644 --- a/docs/framework/vue/reference/functions/useQuery.md +++ b/docs/framework/vue/reference/functions/useQuery.md @@ -29,7 +29,7 @@ See also: [Parameters](#parameters-summary) · [Returns](#returns-summary) function useQuery(options: DefinedInitialQueryOptions, queryClient?: QueryClient): UseQueryDefinedReturnType; ``` -Defined in: [packages/vue-query/src/useQuery.ts:74](https://github.com/TanStack/query/blob/main/packages/vue-query/src/useQuery.ts#L74) +Defined in: [packages/vue-query/src/useQuery.ts:76](https://github.com/TanStack/query/blob/main/packages/vue-query/src/useQuery.ts#L76) This overload is selected when `initialData` is known to be defined, so the resulting `data` is never `undefined` (unless a `select` changes `TData` to include `undefined`). @@ -77,9 +77,11 @@ will be used. [`UseQueryDefinedReturnType`](../type-aliases/UseQueryDefinedReturnType.md)\<`TData`, `TError`\> -The current query result, typed so that `data` is never `undefined` (unless a `select` changes -`TData` to include `undefined`). `status` never resolves to `pending` in this overload's type, since -`initialData` guarantees data upfront. +The current query result, typed so that `status` is `success` — or `error` if a fetch attempt +fails while keeping the existing data (`status` never resolves to `pending` in this overload's type, +since `initialData` guarantees data upfront). `isSuccess`/`isError` are derived boolean `ref`s for +convenience. `state` is that result as one readonly reactive object — `state.data`, `state.isPending`, and +the rest are plain values. ### Example @@ -112,7 +114,7 @@ const { data, isError, error } = useQuery({ function useQuery(options: UndefinedInitialQueryOptions, queryClient?: QueryClient): UseQueryReturnType; ``` -Defined in: [packages/vue-query/src/useQuery.ts:234](https://github.com/TanStack/query/blob/main/packages/vue-query/src/useQuery.ts#L234) +Defined in: [packages/vue-query/src/useQuery.ts:237](https://github.com/TanStack/query/blob/main/packages/vue-query/src/useQuery.ts#L237) `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 @@ -157,9 +159,10 @@ will be used. [`UseQueryReturnType`](../type-aliases/UseQueryReturnType.md)\<`TData`, `TError`\> The current query result. `status` is `pending` if there is no cached data to display, `error` if -the last fetch attempt failed, or `success` if the query has data to display. `state` is that result as one -reactive object — `state.data`, `state.isPending`, and the rest are plain values, and `state.status === 'success'` -narrows `state.data` to `TData`. +the last fetch attempt failed, or `success` if the query has data to display. `isPending`/`isSuccess`/`isError` +are derived boolean `ref`s for convenience. `state` is that result as one readonly reactive object — +`state.data`, `state.isPending`, and the rest are plain values, and `state.status === 'success'` narrows +`state.data` to `TData`. ### Examples @@ -308,7 +311,7 @@ const { state } = useQuery({ function useQuery(options: MaybeRefOrGetter>, queryClient?: QueryClient): UseQueryReturnType; ``` -Defined in: [packages/vue-query/src/useQuery.ts:307](https://github.com/TanStack/query/blob/main/packages/vue-query/src/useQuery.ts#L307) +Defined in: [packages/vue-query/src/useQuery.ts:314](https://github.com/TanStack/query/blob/main/packages/vue-query/src/useQuery.ts#L314) 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 @@ -358,7 +361,11 @@ will be used. [`UseQueryReturnType`](../type-aliases/UseQueryReturnType.md)\<`TData`, `TError`\> -The current query result, with `data` typed as possibly `undefined`. +The current query result. `status` is `pending` if there is no cached data to display, `error` if +the last fetch attempt failed, or `success` if the query has data to display. `isPending`/`isSuccess`/`isError` +are derived boolean `ref`s for convenience. `state` is that result as one readonly reactive object — +`state.data`, `state.isPending`, and the rest are plain values, and `state.status === 'success'` narrows +`state.data` to `TData`. ### Examples @@ -432,4 +439,8 @@ will be used. [`UseQueryReturnType`](../type-aliases/UseQueryReturnType.md)\<`TData`, `TError`\> -The current query result, with `data` typed as possibly `undefined`. +The current query result. `status` is `pending` if there is no cached data to display, `error` if +the last fetch attempt failed, or `success` if the query has data to display. `isPending`/`isSuccess`/`isError` +are derived boolean `ref`s for convenience. `state` is that result as one readonly reactive object — +`state.data`, `state.isPending`, and the rest are plain values, and `state.status === 'success'` narrows +`state.data` to `TData`. diff --git a/packages/vue-query/src/useQuery.ts b/packages/vue-query/src/useQuery.ts index 3c84faca414..24040581e23 100644 --- a/packages/vue-query/src/useQuery.ts +++ b/packages/vue-query/src/useQuery.ts @@ -46,9 +46,11 @@ export type UseQueryDefinedReturnType = UseBaseQueryReturnType< * with `initialData` known to be defined. * @param queryClient - Use this to use a custom `QueryClient`. Otherwise, the one provided by `VueQueryPlugin` * will be used. - * @returns The current query result, typed so that `data` is never `undefined` (unless a `select` changes - * `TData` to include `undefined`). `status` never resolves to `pending` in this overload's type, since - * `initialData` guarantees data upfront. + * @returns The current query result, typed so that `status` is `success` — or `error` if a fetch attempt + * fails while keeping the existing data (`status` never resolves to `pending` in this overload's type, + * since `initialData` guarantees data upfront). `isSuccess`/`isError` are derived boolean `ref`s for + * convenience. `state` is that result as one readonly reactive object — `state.data`, `state.isPending`, and + * the rest are plain values. * @example * ```vue *