@tanstack/vue-query 5.107.0 → 5.107.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (219) hide show
  1. package/README.md +2 -3
  2. package/build/legacy/devtools/devtools.cjs +1 -1
  3. package/build/legacy/devtools/devtools.cjs.map +1 -1
  4. package/build/legacy/devtools/devtools.d.cts +1 -1
  5. package/build/legacy/devtools/devtools.d.ts +1 -1
  6. package/build/legacy/devtools/devtools.js +1 -1
  7. package/build/legacy/devtools/devtools.js.map +1 -1
  8. package/build/legacy/index.cjs +1 -1
  9. package/build/legacy/index.d.cts +4 -4
  10. package/build/legacy/index.d.ts +4 -4
  11. package/build/legacy/index.js +1 -1
  12. package/build/legacy/{infiniteQueryOptions-lJ_zR-As.d.cts → infiniteQueryOptions-CLfd_vOE.d.cts} +61 -17
  13. package/build/legacy/infiniteQueryOptions-CLfd_vOE.d.cts.map +1 -0
  14. package/build/legacy/{infiniteQueryOptions-CN37iZvc.d.ts → infiniteQueryOptions-vEnw-JaW.d.ts} +61 -17
  15. package/build/legacy/infiniteQueryOptions-vEnw-JaW.d.ts.map +1 -0
  16. package/build/legacy/infiniteQueryOptions.d.cts +1 -1
  17. package/build/legacy/infiniteQueryOptions.d.ts +1 -1
  18. package/build/{modern/queryClient-Ba4HSFnn.d.ts → legacy/queryClient-6AWIHAhP.d.ts} +2 -2
  19. package/build/legacy/{queryClient-Ba4HSFnn.d.ts.map → queryClient-6AWIHAhP.d.ts.map} +1 -1
  20. package/build/{modern/queryClient-BGn8uIej.d.cts → legacy/queryClient-yJW8K_VP.d.cts} +2 -2
  21. package/build/legacy/{queryClient-BGn8uIej.d.cts.map → queryClient-yJW8K_VP.d.cts.map} +1 -1
  22. package/build/legacy/queryClient.cjs +1 -1
  23. package/build/legacy/queryClient.cjs.map +1 -1
  24. package/build/legacy/queryClient.d.cts +1 -1
  25. package/build/legacy/queryClient.d.ts +1 -1
  26. package/build/legacy/queryClient.js +1 -1
  27. package/build/legacy/queryClient.js.map +1 -1
  28. package/build/{modern/queryOptions-BuZEBLtg.d.cts → legacy/queryOptions-nndmAASX.d.cts} +22 -11
  29. package/build/legacy/queryOptions-nndmAASX.d.cts.map +1 -0
  30. package/build/{modern/queryOptions-dXiBZnGk.d.ts → legacy/queryOptions-v0l6M7Eo.d.ts} +22 -11
  31. package/build/legacy/queryOptions-v0l6M7Eo.d.ts.map +1 -0
  32. package/build/legacy/queryOptions.cjs.map +1 -1
  33. package/build/legacy/queryOptions.d.cts +2 -2
  34. package/build/legacy/queryOptions.d.ts +2 -2
  35. package/build/legacy/queryOptions.js.map +1 -1
  36. package/build/legacy/types-u_Tu5Ybs.d.cts.map +1 -1
  37. package/build/legacy/types-u_Tu5Ybs.d.ts.map +1 -1
  38. package/build/legacy/useBaseQuery.cjs +11 -5
  39. package/build/legacy/useBaseQuery.cjs.map +1 -1
  40. package/build/legacy/useBaseQuery.d.cts +1 -1
  41. package/build/legacy/useBaseQuery.d.ts +1 -1
  42. package/build/legacy/useBaseQuery.js +11 -5
  43. package/build/legacy/useBaseQuery.js.map +1 -1
  44. package/build/legacy/useInfiniteQuery.cjs.map +1 -1
  45. package/build/legacy/useInfiniteQuery.d.cts +1 -1
  46. package/build/legacy/useInfiniteQuery.d.ts +1 -1
  47. package/build/legacy/useInfiniteQuery.js.map +1 -1
  48. package/build/legacy/useIsFetching.cjs.map +1 -1
  49. package/build/legacy/useIsFetching.d.cts +1 -1
  50. package/build/legacy/useIsFetching.d.ts +1 -1
  51. package/build/legacy/useIsFetching.js.map +1 -1
  52. package/build/legacy/useMutation.cjs.map +1 -1
  53. package/build/legacy/useMutation.d.cts +1 -1
  54. package/build/legacy/useMutation.d.ts +1 -1
  55. package/build/legacy/useMutation.js.map +1 -1
  56. package/build/legacy/useMutationState.cjs.map +1 -1
  57. package/build/legacy/useMutationState.d.cts +1 -1
  58. package/build/legacy/useMutationState.d.ts +1 -1
  59. package/build/legacy/useMutationState.js.map +1 -1
  60. package/build/legacy/usePrefetchInfiniteQuery.cjs.map +1 -1
  61. package/build/legacy/usePrefetchInfiniteQuery.d.cts +1 -1
  62. package/build/legacy/usePrefetchInfiniteQuery.d.ts +1 -1
  63. package/build/legacy/usePrefetchInfiniteQuery.js.map +1 -1
  64. package/build/legacy/usePrefetchQuery.cjs.map +1 -1
  65. package/build/legacy/usePrefetchQuery.d.cts +1 -1
  66. package/build/legacy/usePrefetchQuery.d.ts +1 -1
  67. package/build/legacy/usePrefetchQuery.js.map +1 -1
  68. package/build/legacy/useQueries.cjs +1 -1
  69. package/build/legacy/useQueries.cjs.map +1 -1
  70. package/build/legacy/useQueries.d.cts +2 -2
  71. package/build/legacy/useQueries.d.cts.map +1 -1
  72. package/build/legacy/useQueries.d.ts +2 -2
  73. package/build/legacy/useQueries.d.ts.map +1 -1
  74. package/build/legacy/useQueries.js +1 -1
  75. package/build/legacy/useQueries.js.map +1 -1
  76. package/build/legacy/useQuery.cjs.map +1 -1
  77. package/build/legacy/useQuery.d.cts +56 -22
  78. package/build/legacy/useQuery.d.cts.map +1 -1
  79. package/build/legacy/useQuery.d.ts +56 -22
  80. package/build/legacy/useQuery.d.ts.map +1 -1
  81. package/build/legacy/useQuery.js.map +1 -1
  82. package/build/legacy/useQueryClient.cjs.map +1 -1
  83. package/build/legacy/useQueryClient.d.cts +1 -1
  84. package/build/legacy/useQueryClient.d.cts.map +1 -1
  85. package/build/legacy/useQueryClient.d.ts +1 -1
  86. package/build/legacy/useQueryClient.d.ts.map +1 -1
  87. package/build/legacy/useQueryClient.js.map +1 -1
  88. package/build/legacy/utils.cjs.map +1 -1
  89. package/build/legacy/utils.js.map +1 -1
  90. package/build/legacy/vueQueryPlugin.cjs +1 -1
  91. package/build/legacy/vueQueryPlugin.cjs.map +1 -1
  92. package/build/legacy/vueQueryPlugin.d.cts +1 -1
  93. package/build/legacy/vueQueryPlugin.d.cts.map +1 -1
  94. package/build/legacy/vueQueryPlugin.d.ts +1 -1
  95. package/build/legacy/vueQueryPlugin.d.ts.map +1 -1
  96. package/build/legacy/vueQueryPlugin.js +1 -1
  97. package/build/legacy/vueQueryPlugin.js.map +1 -1
  98. package/build/modern/devtools/devtools.cjs +1 -1
  99. package/build/modern/devtools/devtools.cjs.map +1 -1
  100. package/build/modern/devtools/devtools.d.cts +1 -1
  101. package/build/modern/devtools/devtools.d.ts +1 -1
  102. package/build/modern/devtools/devtools.js +1 -1
  103. package/build/modern/devtools/devtools.js.map +1 -1
  104. package/build/modern/index.cjs +1 -1
  105. package/build/modern/index.d.cts +4 -4
  106. package/build/modern/index.d.ts +4 -4
  107. package/build/modern/index.js +1 -1
  108. package/build/modern/{infiniteQueryOptions-lJ_zR-As.d.cts → infiniteQueryOptions-CLfd_vOE.d.cts} +61 -17
  109. package/build/modern/infiniteQueryOptions-CLfd_vOE.d.cts.map +1 -0
  110. package/build/modern/{infiniteQueryOptions-CN37iZvc.d.ts → infiniteQueryOptions-vEnw-JaW.d.ts} +61 -17
  111. package/build/modern/infiniteQueryOptions-vEnw-JaW.d.ts.map +1 -0
  112. package/build/modern/infiniteQueryOptions.d.cts +1 -1
  113. package/build/modern/infiniteQueryOptions.d.ts +1 -1
  114. package/build/{legacy/queryClient-Ba4HSFnn.d.ts → modern/queryClient-6AWIHAhP.d.ts} +2 -2
  115. package/build/modern/{queryClient-Ba4HSFnn.d.ts.map → queryClient-6AWIHAhP.d.ts.map} +1 -1
  116. package/build/{legacy/queryClient-BGn8uIej.d.cts → modern/queryClient-yJW8K_VP.d.cts} +2 -2
  117. package/build/modern/{queryClient-BGn8uIej.d.cts.map → queryClient-yJW8K_VP.d.cts.map} +1 -1
  118. package/build/modern/queryClient.cjs +1 -1
  119. package/build/modern/queryClient.cjs.map +1 -1
  120. package/build/modern/queryClient.d.cts +1 -1
  121. package/build/modern/queryClient.d.ts +1 -1
  122. package/build/modern/queryClient.js +1 -1
  123. package/build/modern/queryClient.js.map +1 -1
  124. package/build/{legacy/queryOptions-BuZEBLtg.d.cts → modern/queryOptions-nndmAASX.d.cts} +22 -11
  125. package/build/modern/queryOptions-nndmAASX.d.cts.map +1 -0
  126. package/build/{legacy/queryOptions-dXiBZnGk.d.ts → modern/queryOptions-v0l6M7Eo.d.ts} +22 -11
  127. package/build/modern/queryOptions-v0l6M7Eo.d.ts.map +1 -0
  128. package/build/modern/queryOptions.cjs.map +1 -1
  129. package/build/modern/queryOptions.d.cts +2 -2
  130. package/build/modern/queryOptions.d.ts +2 -2
  131. package/build/modern/queryOptions.js.map +1 -1
  132. package/build/modern/types-u_Tu5Ybs.d.cts.map +1 -1
  133. package/build/modern/types-u_Tu5Ybs.d.ts.map +1 -1
  134. package/build/modern/useBaseQuery.cjs +11 -5
  135. package/build/modern/useBaseQuery.cjs.map +1 -1
  136. package/build/modern/useBaseQuery.d.cts +1 -1
  137. package/build/modern/useBaseQuery.d.ts +1 -1
  138. package/build/modern/useBaseQuery.js +11 -5
  139. package/build/modern/useBaseQuery.js.map +1 -1
  140. package/build/modern/useInfiniteQuery.cjs.map +1 -1
  141. package/build/modern/useInfiniteQuery.d.cts +1 -1
  142. package/build/modern/useInfiniteQuery.d.ts +1 -1
  143. package/build/modern/useInfiniteQuery.js.map +1 -1
  144. package/build/modern/useIsFetching.cjs.map +1 -1
  145. package/build/modern/useIsFetching.d.cts +1 -1
  146. package/build/modern/useIsFetching.d.ts +1 -1
  147. package/build/modern/useIsFetching.js.map +1 -1
  148. package/build/modern/useMutation.cjs.map +1 -1
  149. package/build/modern/useMutation.d.cts +1 -1
  150. package/build/modern/useMutation.d.ts +1 -1
  151. package/build/modern/useMutation.js.map +1 -1
  152. package/build/modern/useMutationState.cjs.map +1 -1
  153. package/build/modern/useMutationState.d.cts +1 -1
  154. package/build/modern/useMutationState.d.ts +1 -1
  155. package/build/modern/useMutationState.js.map +1 -1
  156. package/build/modern/usePrefetchInfiniteQuery.cjs.map +1 -1
  157. package/build/modern/usePrefetchInfiniteQuery.d.cts +1 -1
  158. package/build/modern/usePrefetchInfiniteQuery.d.ts +1 -1
  159. package/build/modern/usePrefetchInfiniteQuery.js.map +1 -1
  160. package/build/modern/usePrefetchQuery.cjs.map +1 -1
  161. package/build/modern/usePrefetchQuery.d.cts +1 -1
  162. package/build/modern/usePrefetchQuery.d.ts +1 -1
  163. package/build/modern/usePrefetchQuery.js.map +1 -1
  164. package/build/modern/useQueries.cjs +1 -1
  165. package/build/modern/useQueries.cjs.map +1 -1
  166. package/build/modern/useQueries.d.cts +2 -2
  167. package/build/modern/useQueries.d.cts.map +1 -1
  168. package/build/modern/useQueries.d.ts +2 -2
  169. package/build/modern/useQueries.d.ts.map +1 -1
  170. package/build/modern/useQueries.js +1 -1
  171. package/build/modern/useQueries.js.map +1 -1
  172. package/build/modern/useQuery.cjs.map +1 -1
  173. package/build/modern/useQuery.d.cts +56 -22
  174. package/build/modern/useQuery.d.cts.map +1 -1
  175. package/build/modern/useQuery.d.ts +56 -22
  176. package/build/modern/useQuery.d.ts.map +1 -1
  177. package/build/modern/useQuery.js.map +1 -1
  178. package/build/modern/useQueryClient.cjs.map +1 -1
  179. package/build/modern/useQueryClient.d.cts +1 -1
  180. package/build/modern/useQueryClient.d.cts.map +1 -1
  181. package/build/modern/useQueryClient.d.ts +1 -1
  182. package/build/modern/useQueryClient.d.ts.map +1 -1
  183. package/build/modern/useQueryClient.js.map +1 -1
  184. package/build/modern/utils.cjs.map +1 -1
  185. package/build/modern/utils.js.map +1 -1
  186. package/build/modern/vueQueryPlugin.cjs +1 -1
  187. package/build/modern/vueQueryPlugin.cjs.map +1 -1
  188. package/build/modern/vueQueryPlugin.d.cts +1 -1
  189. package/build/modern/vueQueryPlugin.d.cts.map +1 -1
  190. package/build/modern/vueQueryPlugin.d.ts +1 -1
  191. package/build/modern/vueQueryPlugin.d.ts.map +1 -1
  192. package/build/modern/vueQueryPlugin.js +1 -1
  193. package/build/modern/vueQueryPlugin.js.map +1 -1
  194. package/package.json +12 -2
  195. package/src/devtools/devtools.ts +2 -2
  196. package/src/index.ts +2 -0
  197. package/src/queryClient.ts +12 -12
  198. package/src/queryOptions.ts +40 -23
  199. package/src/types.ts +2 -0
  200. package/src/useBaseQuery.ts +71 -11
  201. package/src/useInfiniteQuery.ts +32 -28
  202. package/src/useIsFetching.ts +2 -2
  203. package/src/useMutation.ts +4 -4
  204. package/src/useMutationState.ts +2 -2
  205. package/src/usePrefetchInfiniteQuery.ts +1 -1
  206. package/src/usePrefetchQuery.ts +1 -1
  207. package/src/useQueries.ts +9 -5
  208. package/src/useQuery.ts +55 -21
  209. package/src/useQueryClient.ts +0 -1
  210. package/src/utils.ts +2 -2
  211. package/src/vueQueryPlugin.ts +2 -3
  212. package/build/legacy/infiniteQueryOptions-CN37iZvc.d.ts.map +0 -1
  213. package/build/legacy/infiniteQueryOptions-lJ_zR-As.d.cts.map +0 -1
  214. package/build/legacy/queryOptions-BuZEBLtg.d.cts.map +0 -1
  215. package/build/legacy/queryOptions-dXiBZnGk.d.ts.map +0 -1
  216. package/build/modern/infiniteQueryOptions-CN37iZvc.d.ts.map +0 -1
  217. package/build/modern/infiniteQueryOptions-lJ_zR-As.d.cts.map +0 -1
  218. package/build/modern/queryOptions-BuZEBLtg.d.cts.map +0 -1
  219. package/build/modern/queryOptions-dXiBZnGk.d.ts.map +0 -1
@@ -1,10 +1,3 @@
1
- import type {
2
- DeepUnwrapRef,
3
- MaybeRef,
4
- MaybeRefDeep,
5
- MaybeRefOrGetter,
6
- ShallowOption,
7
- } from './types'
8
1
  import type {
9
2
  DefaultError,
10
3
  InitialDataFunction,
@@ -14,6 +7,29 @@ import type {
14
7
  QueryKeyWithDataTag,
15
8
  QueryObserverOptions,
16
9
  } from '@tanstack/query-core'
10
+ import type {
11
+ DeepUnwrapRef,
12
+ MaybeRef,
13
+ MaybeRefDeep,
14
+ MaybeRefOrGetter,
15
+ ShallowOption,
16
+ } from './types'
17
+
18
+ /**
19
+ * `enabled` for Vue Query. A `ref` or `computed` is reactive, while a plain boolean isn't tracked on its own. A
20
+ * zero-argument getter (`() => ...`) is reactive too: it is called while tracking dependencies. query-core's
21
+ * `(query) => boolean` is kept as that callback and is not tracked by Vue — a `ref` read inside it is current
22
+ * when core calls it, and a `ref` change does not by itself call it again. The two are told apart by the number
23
+ * of declared parameters, so declare `query` as a required parameter.
24
+ */
25
+ export type VueQueryEnabledOption<
26
+ TQueryFnData,
27
+ TError,
28
+ TQueryData,
29
+ TQueryKey extends QueryKey,
30
+ > =
31
+ | MaybeRefOrGetter<boolean | undefined>
32
+ | QueryBooleanOption<TQueryFnData, TError, TQueryData, TQueryKey>
17
33
 
18
34
  /**
19
35
  * The plain, unwrapped options that `queryOptions` hands back, and what `useQuery`, `useQueries`, and the
@@ -21,7 +37,8 @@ import type {
21
37
  * {@link UseQueryOptions}, which accepts the same options as `ref`s and `computed`s too.
22
38
  * @template TQueryFnData - The type your `queryFn` resolves to.
23
39
  * @template TError - The type of errors your `queryFn` may throw.
24
- * @template TData - The type `data` ends up as after `select` runs.
40
+ * @template TData - The type `data` ends up as after `select` runs. Defaults to `TQueryFnData` when no
41
+ * `select` is used.
25
42
  * @template TQueryData - The type of data stored in the cache, before `select` runs. Defaults to
26
43
  * `TQueryFnData` and can be configured independently of it.
27
44
  * @template TQueryKey - The type of your `queryKey`.
@@ -42,14 +59,12 @@ export type QueryOptions<
42
59
  TQueryKey
43
60
  >
44
61
  ]: Property extends 'enabled'
45
- ?
46
- | MaybeRefOrGetter<boolean | undefined>
47
- | (() => QueryBooleanOption<
48
- TQueryFnData,
49
- TError,
50
- TQueryData,
51
- DeepUnwrapRef<TQueryKey>
52
- >)
62
+ ? VueQueryEnabledOption<
63
+ TQueryFnData,
64
+ TError,
65
+ TQueryData,
66
+ DeepUnwrapRef<TQueryKey>
67
+ >
53
68
  : Property extends 'queryKey'
54
69
  ? MaybeRefOrGetter<TQueryKey>
55
70
  : QueryObserverOptions<
@@ -65,12 +80,13 @@ export type QueryOptions<
65
80
  type SkipTokenForUseQuery = symbol
66
81
 
67
82
  /**
68
- * The options accepted by `queryOptions`, `useQuery`, and the other query hooks. `enabled` tracks reactive
69
- * dependencies automatically as a `ref`, a plain value, or a reactive getter (`() => ...`). `queryKey` reacts
70
- * through a `ref` or a reactive getter for the array itself, or `ref`s and reactive getters as individual
71
- * entries. Other options are read once when passed as a plain value, and stay reactive when passed as a `ref`
72
- * or a `computed`. Only `enabled` and `queryKey` read a function as a getter, so `queryFn` reacts through a
73
- * `computed`: a function there is the query function itself.
83
+ * The options accepted by `queryOptions`, `useQuery`, and the other query hooks. `enabled` accepts a `ref`, a
84
+ * plain boolean, or a zero-argument getter (`() => ...`): a `ref` or a getter is tracked, while a plain boolean
85
+ * isn't tracked on its own. query-core's `(query) => boolean` callback is accepted too and is passed through
86
+ * untracked. `queryKey` reacts through a `ref` or a reactive getter for the array itself, or `ref`s and reactive
87
+ * getters as individual entries. Other options are read once when passed as a plain value, and stay reactive
88
+ * when passed as a `ref` or a `computed`. Only `enabled` and `queryKey` read a function as a getter, so
89
+ * `queryFn` reacts through a `computed`: a function there is the query function itself.
74
90
  *
75
91
  * If you instead pass a getter for the whole options object (`useQuery(() => ({ ... }))`), every option
76
92
  * inside it — including `staleTime`, `retry`, and `select` — is re-evaluated whenever the getter's own
@@ -83,7 +99,8 @@ type SkipTokenForUseQuery = symbol
83
99
  * re-evaluates.
84
100
  * @template TQueryFnData - The type your `queryFn` resolves to.
85
101
  * @template TError - The type of errors your `queryFn` may throw.
86
- * @template TData - The type `data` ends up as after `select` runs.
102
+ * @template TData - The type `data` ends up as after `select` runs. Defaults to `TQueryFnData` when no
103
+ * `select` is used.
87
104
  * @template TQueryData - The type of data stored in the cache, before `select` runs. Defaults to
88
105
  * `TQueryFnData` and can be configured independently of it.
89
106
  * @template TQueryKey - The type of your `queryKey`.
package/src/types.ts CHANGED
@@ -13,6 +13,7 @@ import type { ComputedRef, Ref, UnwrapRef } from 'vue-demi'
13
13
  type Primitive = string | number | boolean | bigint | symbol | undefined | null
14
14
  type UnwrapLeaf =
15
15
  | Primitive
16
+ // oxlint-disable-next-line typescript/no-unsafe-function-type -- leaves every function-like value, including constructors, unwrapped
16
17
  | Function
17
18
  | Date
18
19
  | Error
@@ -44,6 +45,7 @@ export type MaybeRefOrGetter<T> = MaybeRef<T> | (() => T)
44
45
  * object as a whole.
45
46
  */
46
47
  export type MaybeRefDeep<T> = MaybeRef<
48
+ // oxlint-disable-next-line typescript/no-unsafe-function-type -- keeps every function-like value, including constructors, as it is
47
49
  T extends Function
48
50
  ? T
49
51
  : T extends object
@@ -1,3 +1,4 @@
1
+ import { shouldThrowError } from '@tanstack/query-core'
1
2
  import {
2
3
  computed,
3
4
  getCurrentScope,
@@ -9,24 +10,31 @@ import {
9
10
  toRefs,
10
11
  watch,
11
12
  } from 'vue-demi'
12
- import { shouldThrowError } from '@tanstack/query-core'
13
13
  import { useQueryClient } from './useQueryClient'
14
14
  import { cloneDeepUnref, updateState } from './utils'
15
- import type { Ref } from 'vue-demi'
16
15
  import type {
17
16
  DefaultedQueryObserverOptions,
18
17
  QueryKey,
19
18
  QueryObserver,
20
19
  QueryObserverResult,
21
20
  } from '@tanstack/query-core'
21
+ import type { Ref } from 'vue-demi'
22
22
  import type { QueryClient } from './queryClient'
23
23
  import type { UseQueryOptions } from './queryOptions'
24
- import type { UseInfiniteQueryOptions } from './useInfiniteQuery'
25
24
  import type { MaybeRefOrGetter } from './types'
25
+ import type { UseInfiniteQueryOptions } from './useInfiniteQuery'
26
+
27
+ /**
28
+ * Readonly view of a union that stays a union. A single `Readonly<Union>` collapses the members, which
29
+ * drops the `status` / `isSuccess` / `isPending` discriminants.
30
+ */
31
+ type ReadonlyQueryState<T> = T extends any
32
+ ? { readonly [K in keyof T]: T[K] }
33
+ : never
26
34
 
27
35
  /**
28
36
  * The result of the query composables: every property of the observer result wrapped in a `Ref`, except
29
- * the `refetch`, `fetchNextPage`, and `fetchPreviousPage` functions, plus `suspense`.
37
+ * the `refetch`, `fetchNextPage`, and `fetchPreviousPage` functions, plus `suspense` and `state`.
30
38
  */
31
39
  export type UseBaseQueryReturnType<
32
40
  TData,
@@ -49,6 +57,37 @@ export type UseBaseQueryReturnType<
49
57
  * `true`, in which case it rejects.
50
58
  */
51
59
  suspense: () => Promise<TResult>
60
+ /**
61
+ * The query result as one readonly reactive object. `data`, `error`, `status`, `isPending`, and the other
62
+ * fields are plain values — read `state.data`, not `state.data.value`.
63
+ *
64
+ * The object is a discriminated union, so a check on `status`, `isSuccess`, `isPending`, or `isError`
65
+ * narrows the other fields. When `status` is `'success'` (or `isSuccess` is `true`), `data` is `TData`.
66
+ * When `status` is `'pending'` (or `isPending` is `true`), `data` is `undefined` and `error` is `null`.
67
+ * @example
68
+ * ```vue
69
+ * <script setup lang="ts">
70
+ * import { useQuery } from '@tanstack/vue-query'
71
+ *
72
+ * const { state } = useQuery({
73
+ * queryKey: ['post'],
74
+ * queryFn: fetchPost,
75
+ * })
76
+ *
77
+ * if (state.status === 'success') {
78
+ * // `state.data` is `Post`, not `Post | undefined`
79
+ * console.log(state.data.title)
80
+ * }
81
+ * </script>
82
+ *
83
+ * <template>
84
+ * <span v-if="state.status === 'pending'">Loading...</span>
85
+ * <span v-else-if="state.status === 'error'">Error: {{ state.error.message }}</span>
86
+ * <h1 v-else>{{ state.data.title }}</h1>
87
+ * </template>
88
+ * ```
89
+ */
90
+ state: ReadonlyQueryState<TResult>
52
91
  }
53
92
 
54
93
  type UseQueryOptionsGeneric<
@@ -108,7 +147,12 @@ export function useBaseQuery<
108
147
  }
109
148
  const clonedOptions = cloneDeepUnref(resolvedOptions as any)
110
149
 
111
- if (typeof clonedOptions.enabled === 'function') {
150
+ // A zero-arg function is a Vue getter and must run here so its refs are tracked.
151
+ // `(query) => boolean` is query-core's callback and is left for core to call.
152
+ if (
153
+ typeof clonedOptions.enabled === 'function' &&
154
+ clonedOptions.enabled.length === 0
155
+ ) {
112
156
  clonedOptions.enabled = clonedOptions.enabled()
113
157
  }
114
158
 
@@ -137,6 +181,11 @@ export function useBaseQuery<
137
181
  // noop
138
182
  }
139
183
 
184
+ // Replaced below with the wrapper. Declared here so the subscriber can put it
185
+ // back after `updateState` copies the observer's own `refetch` onto `state`.
186
+ let refetch: (typeof state)['refetch'] = (...args) =>
187
+ observer.refetch(...args)
188
+
140
189
  if (client.isRestoring) {
141
190
  watch(
142
191
  client.isRestoring,
@@ -145,6 +194,7 @@ export function useBaseQuery<
145
194
  unsubscribe()
146
195
  unsubscribe = observer.subscribe((result) => {
147
196
  updateState(state, result)
197
+ state.refetch = refetch
148
198
  })
149
199
  }
150
200
  },
@@ -155,6 +205,7 @@ export function useBaseQuery<
155
205
  const updater = () => {
156
206
  observer.setOptions(defaultedOptions.value)
157
207
  updateState(state, observer.getCurrentResult())
208
+ state.refetch = refetch
158
209
  }
159
210
 
160
211
  watch(defaultedOptions, updater)
@@ -163,11 +214,13 @@ export function useBaseQuery<
163
214
  unsubscribe()
164
215
  })
165
216
 
166
- // fix #5910
167
- const refetch = (...args: Parameters<(typeof state)['refetch']>) => {
217
+ // fix #5910. Call `observer.refetch`: `state.refetch` is this wrapper, so
218
+ // calling it would recurse.
219
+ refetch = (...args) => {
168
220
  updater()
169
- return state.refetch(...args)
221
+ return observer.refetch(...args)
170
222
  }
223
+ state.refetch = refetch
171
224
 
172
225
  const suspense = () => {
173
226
  return new Promise<QueryObserverResult<TData, TError>>(
@@ -176,9 +229,15 @@ export function useBaseQuery<
176
229
  // noop
177
230
  }
178
231
  const run = () => {
179
- if (defaultedOptions.value.enabled !== false) {
180
- // fix #6133
181
- observer.setOptions(defaultedOptions.value)
232
+ // Apply the latest options before resolving `enabled`, so a query callback sees the current query.
233
+ // fix #6133
234
+ observer.setOptions(defaultedOptions.value)
235
+ const { enabled } = defaultedOptions.value
236
+ if (
237
+ (typeof enabled === 'function'
238
+ ? enabled(observer.getCurrentQuery())
239
+ : enabled) !== false
240
+ ) {
182
241
  const optimisticResult = observer.getOptimisticResult(
183
242
  defaultedOptions.value,
184
243
  )
@@ -243,6 +302,7 @@ export function useBaseQuery<
243
302
 
244
303
  object.suspense = suspense
245
304
  object.refetch = refetch
305
+ object.state = readonlyState
246
306
 
247
307
  return object as UseBaseQueryReturnType<TData, TError>
248
308
  }
@@ -1,9 +1,5 @@
1
1
  import { InfiniteQueryObserver } from '@tanstack/query-core'
2
2
  import { useBaseQuery } from './useBaseQuery'
3
- import type {
4
- DefinedInitialDataInfiniteOptions,
5
- UndefinedInitialDataInfiniteOptions,
6
- } from './infiniteQueryOptions'
7
3
  import type {
8
4
  DefaultError,
9
5
  DefinedInfiniteQueryObserverResult,
@@ -13,9 +9,12 @@ import type {
13
9
  QueryKey,
14
10
  QueryObserver,
15
11
  } from '@tanstack/query-core'
16
-
17
- import type { UseBaseQueryReturnType } from './useBaseQuery'
18
-
12
+ import type {
13
+ DefinedInitialDataInfiniteOptions,
14
+ UndefinedInitialDataInfiniteOptions,
15
+ } from './infiniteQueryOptions'
16
+ import type { QueryClient } from './queryClient'
17
+ import type { VueQueryEnabledOption } from './queryOptions'
19
18
  import type {
20
19
  DeepUnwrapRef,
21
20
  MaybeRef,
@@ -23,12 +22,17 @@ import type {
23
22
  MaybeRefOrGetter,
24
23
  ShallowOption,
25
24
  } from './types'
26
- import type { QueryClient } from './queryClient'
25
+ import type { UseBaseQueryReturnType } from './useBaseQuery'
27
26
 
28
27
  /**
29
- * The options accepted by `useInfiniteQuery`. Same as {@link InfiniteQueryObserverOptions} from
30
- * `@tanstack/query-core`, plus the `shallow` option. Each option except `shallow` can also be a `ref` (and
31
- * `enabled` a reactive getter).
28
+ * The options accepted by `useInfiniteQuery`. Extends {@link InfiniteQueryObserverOptions} from
29
+ * `@tanstack/query-core` with the `vue-query`-specific `shallow` option. Each option except `shallow` can also
30
+ * be a `ref` (and `enabled` a zero-argument getter or query-core's `(query) => boolean` callback).
31
+ * @template TQueryFnData - The type of a single page, as your `queryFn` resolves it.
32
+ * @template TError - The type of errors your `queryFn` may throw.
33
+ * @template TData - The type `data` ends up as after `select` runs — defaults to `TQueryFnData`.
34
+ * @template TQueryKey - The type of your `queryKey`.
35
+ * @template TPageParam - The type of the parameter passed to `queryFn` to fetch a given page.
32
36
  */
33
37
  export type UseInfiniteQueryOptions<
34
38
  TQueryFnData = unknown,
@@ -47,14 +51,11 @@ export type UseInfiniteQueryOptions<
47
51
  TPageParam
48
52
  >
49
53
  ]: Property extends 'enabled'
50
- ? MaybeRefOrGetter<
51
- InfiniteQueryObserverOptions<
52
- TQueryFnData,
53
- TError,
54
- TData,
55
- DeepUnwrapRef<TQueryKey>,
56
- TPageParam
57
- >[Property]
54
+ ? VueQueryEnabledOption<
55
+ TQueryFnData,
56
+ TError,
57
+ InfiniteData<TQueryFnData, TPageParam>,
58
+ DeepUnwrapRef<TQueryKey>
58
59
  >
59
60
  : MaybeRefDeep<
60
61
  InfiniteQueryObserverOptions<
@@ -96,9 +97,10 @@ export type UseInfiniteQueryDefinedReturnType<TData, TError> =
96
97
  * This overload is selected when `initialData` is known to be defined, so the resulting `data` is never
97
98
  * `undefined` (unless a `select` changes `TData` to include `undefined`).
98
99
  *
99
- * `enabled` tracks reactive dependencies automatically as a `ref`, a plain value, or a reactive getter
100
- * (`() => ...`). `queryKey` reacts through a `ref` for the array itself, or `ref`s and reactive getters as
101
- * individual entries — the array itself can't be a bare getter.
100
+ * `enabled` accepts a `ref`, a plain boolean, or a zero-argument getter (`() => ...`): a `ref` or a getter is
101
+ * tracked, while a plain boolean isn't tracked on its own. query-core's `(query) => boolean` callback is
102
+ * accepted too and is passed through untracked. `queryKey` reacts through a `ref` for the array itself, or
103
+ * `ref`s and reactive getters as individual entries — the array itself can't be a bare getter.
102
104
  * @param options - The {@link DefinedInitialDataInfiniteOptions} to use — everything you can pass to
103
105
  * `useInfiniteQuery`, with `initialData` known to be defined.
104
106
  * @param queryClient - Use this to use a custom `QueryClient`. Otherwise, the one provided by `VueQueryPlugin`
@@ -159,9 +161,10 @@ export function useInfiniteQuery<
159
161
  * The options for `useInfiniteQuery` are identical to `useQuery`, with the addition of
160
162
  * `initialPageParam`, `getNextPageParam`, `getPreviousPageParam`, and `maxPages`.
161
163
  *
162
- * `enabled` tracks reactive dependencies automatically as a `ref`, a plain value, or a reactive getter
163
- * (`() => ...`). `queryKey` reacts through a `ref` for the array itself, or `ref`s and reactive getters as
164
- * individual entries — the array itself can't be a bare getter.
164
+ * `enabled` accepts a `ref`, a plain boolean, or a zero-argument getter (`() => ...`): a `ref` or a getter is
165
+ * tracked, while a plain boolean isn't tracked on its own. query-core's `(query) => boolean` callback is
166
+ * accepted too and is passed through untracked. `queryKey` reacts through a `ref` for the array itself, or
167
+ * `ref`s and reactive getters as individual entries — the array itself can't be a bare getter.
165
168
  * @param options - The {@link UndefinedInitialDataInfiniteOptions} to use — everything you can pass to
166
169
  * `useInfiniteQuery`.
167
170
  * @param queryClient - Use this to use a custom `QueryClient`. Otherwise, the one provided by `VueQueryPlugin`
@@ -291,9 +294,10 @@ export function useInfiniteQuery<
291
294
  * `ref`/reactive object built up conditionally, rather than a plain object literal. Prefer one of the other
292
295
  * overloads when possible, since they infer whether `data` can be `undefined` from `initialData` directly.
293
296
  *
294
- * `enabled` tracks reactive dependencies automatically as a `ref`, a plain value, or a reactive getter
295
- * (`() => ...`). `queryKey` reacts through a `ref` for the array itself, or `ref`s and reactive getters as
296
- * individual entries — the array itself can't be a bare getter.
297
+ * `enabled` accepts a `ref`, a plain boolean, or a zero-argument getter (`() => ...`): a `ref` or a getter is
298
+ * tracked, while a plain boolean isn't tracked on its own. query-core's `(query) => boolean` callback is
299
+ * accepted too and is passed through untracked. `queryKey` reacts through a `ref` for the array itself, or
300
+ * `ref`s and reactive getters as individual entries — the array itself can't be a bare getter.
297
301
  * @param options - A `ref`, plain value, or reactive getter resolving to the {@link UseInfiniteQueryOptions} to
298
302
  * use.
299
303
  * @param queryClient - Use this to use a custom `QueryClient`. Otherwise, the one provided by `VueQueryPlugin`
@@ -1,10 +1,10 @@
1
1
  import { getCurrentScope, onScopeDispose, ref, watchEffect } from 'vue-demi'
2
2
  import { useQueryClient } from './useQueryClient'
3
3
  import { cloneDeepUnref } from './utils'
4
- import type { Ref } from 'vue-demi'
5
4
  import type { QueryFilters } from '@tanstack/query-core'
6
- import type { MaybeRefDeep } from './types'
5
+ import type { Ref } from 'vue-demi'
7
6
  import type { QueryClient } from './queryClient'
7
+ import type { MaybeRefDeep } from './types'
8
8
 
9
9
  /**
10
10
  * The filters accepted by `useIsFetching`: {@link QueryFilters} as a plain object, a `ref`, or a reactive
@@ -1,3 +1,4 @@
1
+ import { MutationObserver, shouldThrowError } from '@tanstack/query-core'
1
2
  import {
2
3
  computed,
3
4
  getCurrentScope,
@@ -9,18 +10,17 @@ import {
9
10
  toRefs,
10
11
  watch,
11
12
  } from 'vue-demi'
12
- import { MutationObserver, shouldThrowError } from '@tanstack/query-core'
13
- import { cloneDeepUnref, updateState } from './utils'
14
13
  import { useQueryClient } from './useQueryClient'
15
- import type { ToRefs } from 'vue-demi'
14
+ import { cloneDeepUnref, updateState } from './utils'
16
15
  import type {
17
16
  DefaultError,
18
17
  DistributiveOmit,
19
18
  MutateFunction,
20
19
  MutationObserverResult,
21
20
  } from '@tanstack/query-core'
22
- import type { MaybeRefDeep, MutationOptions } from './types'
21
+ import type { ToRefs } from 'vue-demi'
23
22
  import type { QueryClient } from './queryClient'
23
+ import type { MaybeRefDeep, MutationOptions } from './types'
24
24
 
25
25
  /**
26
26
  * The {@link MutationObserverResult} properties without `mutate` and `reset`, which `useMutation` replaces with
@@ -8,15 +8,15 @@ import {
8
8
  } from 'vue-demi'
9
9
  import { useQueryClient } from './useQueryClient'
10
10
  import { cloneDeepUnref } from './utils'
11
- import type { Ref } from 'vue-demi'
12
11
  import type {
13
12
  Mutation,
14
13
  MutationFilters,
15
14
  MutationState,
16
15
  } from '@tanstack/query-core'
16
+ import type { Ref } from 'vue-demi'
17
+ import type { MutationCache } from './mutationCache'
17
18
  import type { QueryClient } from './queryClient'
18
19
  import type { MaybeRefDeep } from './types'
19
- import type { MutationCache } from './mutationCache'
20
20
 
21
21
  type VueMutationFilters = MaybeRefDeep<MutationFilters>
22
22
 
@@ -1,5 +1,5 @@
1
- import { getCurrentScope, unref, watchEffect } from 'vue-demi'
2
1
  import { noop } from '@tanstack/query-core'
2
+ import { getCurrentScope, unref, watchEffect } from 'vue-demi'
3
3
  import { useQueryClient } from './useQueryClient'
4
4
  import { cloneDeepUnref } from './utils'
5
5
  import type {
@@ -1,5 +1,5 @@
1
- import { getCurrentScope, unref, watchEffect } from 'vue-demi'
2
1
  import { noop } from '@tanstack/query-core'
2
+ import { getCurrentScope, unref, watchEffect } from 'vue-demi'
3
3
  import { useQueryClient } from './useQueryClient'
4
4
  import { cloneDeepUnref } from './utils'
5
5
  import type {
package/src/useQueries.ts CHANGED
@@ -9,10 +9,8 @@ import {
9
9
  unref,
10
10
  watch,
11
11
  } from 'vue-demi'
12
-
13
12
  import { useQueryClient } from './useQueryClient'
14
13
  import { cloneDeepUnref } from './utils'
15
- import type { Ref } from 'vue-demi'
16
14
  import type {
17
15
  DefaultError,
18
16
  DefinedQueryObserverResult,
@@ -22,8 +20,9 @@ import type {
22
20
  QueryObserverResult,
23
21
  ThrowOnError,
24
22
  } from '@tanstack/query-core'
25
- import type { UseQueryOptions } from './queryOptions'
23
+ import type { Ref } from 'vue-demi'
26
24
  import type { QueryClient } from './queryClient'
25
+ import type { UseQueryOptions } from './queryOptions'
27
26
  import type { DeepUnwrapRef, MaybeRefDeep, ShallowOption } from './types'
28
27
 
29
28
  // This defines the `UseQueryOptions` that are accepted in `QueriesOptions` & `GetOptions`.
@@ -393,8 +392,13 @@ export function useQueries<
393
392
  return queriesRaw.map((queryOptions) => {
394
393
  const clonedOptions = cloneDeepUnref(queryOptions)
395
394
 
396
- if (typeof clonedOptions.enabled === 'function') {
397
- clonedOptions.enabled = queryOptions.enabled()
395
+ // A zero-arg function is a Vue getter and must run here so its refs are tracked.
396
+ // `(query) => boolean` is query-core's callback and is left for core to call.
397
+ if (
398
+ typeof clonedOptions.enabled === 'function' &&
399
+ clonedOptions.enabled.length === 0
400
+ ) {
401
+ clonedOptions.enabled = clonedOptions.enabled()
398
402
  }
399
403
 
400
404
  const defaulted = client.defaultQueryOptions(clonedOptions)
package/src/useQuery.ts CHANGED
@@ -5,14 +5,14 @@ import type {
5
5
  DefinedQueryObserverResult,
6
6
  QueryKey,
7
7
  } from '@tanstack/query-core'
8
- import type { UseBaseQueryReturnType } from './useBaseQuery'
9
- import type { MaybeRefOrGetter } from './types'
10
8
  import type { QueryClient } from './queryClient'
11
9
  import type {
12
10
  DefinedInitialQueryOptions,
13
11
  UndefinedInitialQueryOptions,
14
12
  UseQueryOptions,
15
13
  } from './queryOptions'
14
+ import type { MaybeRefOrGetter } from './types'
15
+ import type { UseBaseQueryReturnType } from './useBaseQuery'
16
16
 
17
17
  /**
18
18
  * The result of `useQuery` when `initialData` is omitted, may be `undefined`, or is a function that may
@@ -35,20 +35,24 @@ export type UseQueryDefinedReturnType<TData, TError> = UseBaseQueryReturnType<
35
35
  >
36
36
 
37
37
  /**
38
- * This overload is selected when `initialData` is known to be defined, so the resulting `data` is never
39
- * `undefined` (unless a `select` changes `TData` to include `undefined`).
38
+ * This overload is selected when `initialData` is known to be defined, so the resulting `data` is typed as never
39
+ * `undefined` (unless a `select` changes `TData` to include `undefined`). At runtime, `data` is still `undefined`
40
+ * if `select` throws on its first call.
40
41
  *
41
- * `enabled` tracks reactive dependencies automatically as a `ref`, a plain value, or a reactive getter
42
- * (`() => ...`). `queryKey` reacts through a `ref` or a reactive getter for the array itself, or `ref`s and
43
- * reactive getters as individual entries. Other options are read once when passed as a plain value, and stay
44
- * reactive when passed as a `ref` or a `computed`.
42
+ * `enabled` accepts a `ref`, a plain boolean, or a zero-argument getter (`() => ...`): a `ref` or a getter is
43
+ * tracked, while a plain boolean isn't tracked on its own. query-core's `(query) => boolean` callback is
44
+ * accepted too and is passed through untracked. `queryKey` reacts through a `ref` or a reactive getter for the
45
+ * array itself, or `ref`s and reactive getters as individual entries. Other options are read once when passed as
46
+ * a plain value, and stay reactive when passed as a `ref` or a `computed`.
45
47
  * @param options - The {@link DefinedInitialQueryOptions} to use — everything you can pass to `useQuery`,
46
48
  * with `initialData` known to be defined.
47
49
  * @param queryClient - Use this to use a custom `QueryClient`. Otherwise, the one provided by `VueQueryPlugin`
48
50
  * will be used.
49
- * @returns The current query result, typed so that `data` is never `undefined` (unless a `select` changes
50
- * `TData` to include `undefined`). `status` never resolves to `pending` in this overload's type, since
51
- * `initialData` guarantees data upfront.
51
+ * @returns The current query result, typed so that `status` is `success` or `error` (`status` never resolves
52
+ * to `pending` in this overload's type, since `initialData` guarantees data upfront). `status` is `error` if
53
+ * the query has an error from a fetch that failed after its retries or if `select` threw, and `success`
54
+ * otherwise. `isSuccess`/`isError` are derived boolean `ref`s for convenience. `state` is that result as one
55
+ * readonly reactive object — `state.data`, `state.isPending`, and the rest are plain values.
52
56
  * @example
53
57
  * ```vue
54
58
  * <script setup lang="ts">
@@ -82,15 +86,20 @@ export function useQuery<
82
86
  ): UseQueryDefinedReturnType<TData, TError>
83
87
 
84
88
  /**
85
- * `enabled` tracks reactive dependencies automatically as a `ref`, a plain value, or a reactive getter
86
- * (`() => ...`). `queryKey` reacts through a `ref` or a reactive getter for the array itself, or `ref`s and
87
- * reactive getters as individual entries. Other options are read once when passed as a plain value, and stay
88
- * reactive when passed as a `ref` or a `computed`.
89
+ * `enabled` accepts a `ref`, a plain boolean, or a zero-argument getter (`() => ...`): a `ref` or a getter is
90
+ * tracked, while a plain boolean isn't tracked on its own. query-core's `(query) => boolean` callback is
91
+ * accepted too and is passed through untracked. `queryKey` reacts through a `ref` or a reactive getter for the
92
+ * array itself, or `ref`s and reactive getters as individual entries. Other options are read once when passed as
93
+ * a plain value, and stay reactive when passed as a `ref` or a `computed`.
89
94
  * @param options - The {@link UndefinedInitialQueryOptions} to use — everything you can pass to `useQuery`.
90
95
  * @param queryClient - Use this to use a custom `QueryClient`. Otherwise, the one provided by `VueQueryPlugin`
91
96
  * will be used.
92
- * @returns The current query result. `status` is `pending` if there is no cached data to display, `error` if
93
- * the last fetch attempt failed, or `success` if the query has data to display.
97
+ * @returns The current query result. `status` is `error` if the query has an error from a fetch that failed
98
+ * after its retries or if `select` threw, `success` if the query has cached data (even if `select` returns
99
+ * `undefined`) or data from `placeholderData`, and `pending` otherwise. `isPending`/`isSuccess`/`isError` are
100
+ * derived boolean `ref`s for convenience. `state` is that result as one readonly reactive object —
101
+ * `state.data`, `state.isPending`, and the rest are plain values, and `state.status === 'success'` narrows
102
+ * `state.data` to `TData`.
94
103
  * @example
95
104
  * A query key built from a reactive `ref` — the query refetches whenever `postId` changes:
96
105
  * ```vue
@@ -209,6 +218,25 @@ export function useQuery<
209
218
  * </template>
210
219
  * </template>
211
220
  * ```
221
+ * @example
222
+ * `state` keeps `data`, `error`, `status`, and `isPending` on one reactive object, so a `status` check
223
+ * narrows `data` and you never read `.value`:
224
+ * ```vue
225
+ * <script setup lang="ts">
226
+ * import { useQuery } from '@tanstack/vue-query'
227
+ *
228
+ * const { state } = useQuery({
229
+ * queryKey: ['post'],
230
+ * queryFn: fetchPost,
231
+ * })
232
+ * </script>
233
+ *
234
+ * <template>
235
+ * <span v-if="state.status === 'pending'">Loading...</span>
236
+ * <span v-else-if="state.status === 'error'">Error: {{ state.error.message }}</span>
237
+ * <h1 v-else>{{ state.data.title }}</h1>
238
+ * </template>
239
+ * ```
212
240
  */
213
241
  export function useQuery<
214
242
  TQueryFnData = unknown,
@@ -225,16 +253,22 @@ export function useQuery<
225
253
  * `ref`/reactive object built up conditionally, rather than a plain object literal. Prefer one of the other
226
254
  * overloads when possible, since they infer whether `data` can be `undefined` from `initialData` directly.
227
255
  *
228
- * `enabled` tracks reactive dependencies automatically as a `ref`, a plain value, or a reactive getter
229
- * (`() => ...`). `queryKey` reacts through a `ref` or a reactive getter for the array itself, or `ref`s and
230
- * reactive getters as individual entries.
256
+ * `enabled` accepts a `ref`, a plain boolean, or a zero-argument getter (`() => ...`): a `ref` or a getter is
257
+ * tracked, while a plain boolean isn't tracked on its own. query-core's `(query) => boolean` callback is
258
+ * accepted too and is passed through untracked. `queryKey` reacts through a `ref` or a reactive getter for the
259
+ * array itself, or `ref`s and reactive getters as individual entries.
231
260
  *
232
261
  * When `options` itself is a reactive getter, the whole object is re-evaluated on every change to its
233
262
  * dependencies, so any option inside it — not just `queryKey` and `enabled` — can change over time.
234
263
  * @param options - A `ref`, plain value, or reactive getter resolving to the {@link UseQueryOptions} to use.
235
264
  * @param queryClient - Use this to use a custom `QueryClient`. Otherwise, the one provided by `VueQueryPlugin`
236
265
  * will be used.
237
- * @returns The current query result, with `data` typed as possibly `undefined`.
266
+ * @returns The current query result. `status` is `error` if the query has an error from a fetch that failed
267
+ * after its retries or if `select` threw, `success` if the query has cached data (even if `select` returns
268
+ * `undefined`) or data from `placeholderData`, and `pending` otherwise. `isPending`/`isSuccess`/`isError` are
269
+ * derived boolean `ref`s for convenience. `state` is that result as one readonly reactive object —
270
+ * `state.data`, `state.isPending`, and the rest are plain values, and `state.status === 'success'` narrows
271
+ * `state.data` to `TData`.
238
272
  * @example
239
273
  * Passing a whole-options getter so `staleTime` reacts to a setting stored elsewhere, not just `queryKey`:
240
274
  * ```vue
@@ -1,5 +1,4 @@
1
1
  import { hasInjectionContext, inject } from 'vue-demi'
2
-
3
2
  import { getClientKey } from './utils'
4
3
  import type { QueryClient } from './queryClient'
5
4