Repository navigation
docs(vue-query/useQuery): describe the 'status', derived boolean 'ref's, and readonly 'state' in every '@returns' #12548
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -46,9 +46,11 @@ export type UseQueryDefinedReturnType<TData, TError> = 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 | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Qualify readonly behavior for Vue 2.6. With Vue 2.6, the default Also applies to: 96-96, 263-263
|
||
| * the rest are plain values. | ||
| * @example | ||
| * ```vue | ||
| * <script setup lang="ts"> | ||
|
|
@@ -90,9 +92,10 @@ export function useQuery< | |
| * @param queryClient - Use this to use a custom `QueryClient`. Otherwise, the one provided by `VueQueryPlugin` | ||
| * will be used. | ||
| * @returns 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` | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Correct the status conditions. A failed attempt can leave Also applies to: 261-262
|
||
| * 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`. | ||
| * @example | ||
| * A query key built from a reactive `ref` — the query refetches whenever `postId` changes: | ||
| * ```vue | ||
|
|
@@ -255,7 +258,11 @@ export function useQuery< | |
| * @param options - A `ref`, plain value, or reactive getter resolving to the {@link UseQueryOptions} to use. | ||
| * @param queryClient - Use this to use a custom `QueryClient`. Otherwise, the one provided by `VueQueryPlugin` | ||
| * will be used. | ||
| * @returns The current query result, with `data` typed as possibly `undefined`. | ||
| * @returns 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`. | ||
| * @example | ||
| * Passing a whole-options getter so `staleTime` reacts to a setting stored elsewhere, not just `queryKey`: | ||
| * ```vue | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Describe selector errors separately.
If
selectthrows on its first call, the observer reportserrorwithdataundefined, even wheninitialDataexists. No fetch needs to fail. Distinguish the declared type from this runtime case so callers do not rely on retained data. (raw.githubusercontent.com)