@tanstack/preact-query 5.102.3 → 5.102.5

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 (296) hide show
  1. package/build/legacy/HydrationBoundary.cjs +43 -0
  2. package/build/legacy/HydrationBoundary.cjs.map +1 -1
  3. package/build/legacy/HydrationBoundary.d.cts +61 -0
  4. package/build/legacy/HydrationBoundary.d.cts.map +1 -1
  5. package/build/legacy/HydrationBoundary.d.ts +61 -0
  6. package/build/legacy/HydrationBoundary.d.ts.map +1 -1
  7. package/build/legacy/HydrationBoundary.js +43 -0
  8. package/build/legacy/HydrationBoundary.js.map +1 -1
  9. package/build/legacy/IsRestoringProvider.cjs +11 -0
  10. package/build/legacy/IsRestoringProvider.cjs.map +1 -1
  11. package/build/legacy/IsRestoringProvider.d.cts +11 -0
  12. package/build/legacy/IsRestoringProvider.d.cts.map +1 -1
  13. package/build/legacy/IsRestoringProvider.d.ts +11 -0
  14. package/build/legacy/IsRestoringProvider.d.ts.map +1 -1
  15. package/build/legacy/IsRestoringProvider.js +11 -0
  16. package/build/legacy/IsRestoringProvider.js.map +1 -1
  17. package/build/legacy/QueryClientProvider.cjs +30 -0
  18. package/build/legacy/QueryClientProvider.cjs.map +1 -1
  19. package/build/legacy/QueryClientProvider.d.cts +41 -0
  20. package/build/legacy/QueryClientProvider.d.cts.map +1 -1
  21. package/build/legacy/QueryClientProvider.d.ts +41 -0
  22. package/build/legacy/QueryClientProvider.d.ts.map +1 -1
  23. package/build/legacy/QueryClientProvider.js +30 -0
  24. package/build/legacy/QueryClientProvider.js.map +1 -1
  25. package/build/legacy/QueryErrorResetBoundary.cjs +77 -0
  26. package/build/legacy/QueryErrorResetBoundary.cjs.map +1 -1
  27. package/build/legacy/QueryErrorResetBoundary.d.cts +108 -0
  28. package/build/legacy/QueryErrorResetBoundary.d.cts.map +1 -1
  29. package/build/legacy/QueryErrorResetBoundary.d.ts +108 -0
  30. package/build/legacy/QueryErrorResetBoundary.d.ts.map +1 -1
  31. package/build/legacy/QueryErrorResetBoundary.js +77 -0
  32. package/build/legacy/QueryErrorResetBoundary.js.map +1 -1
  33. package/build/legacy/infiniteQueryOptions.cjs.map +1 -1
  34. package/build/legacy/infiniteQueryOptions.d.cts +187 -0
  35. package/build/legacy/infiniteQueryOptions.d.cts.map +1 -1
  36. package/build/legacy/infiniteQueryOptions.d.ts +187 -0
  37. package/build/legacy/infiniteQueryOptions.d.ts.map +1 -1
  38. package/build/legacy/infiniteQueryOptions.js.map +1 -1
  39. package/build/legacy/mutationOptions.cjs.map +1 -1
  40. package/build/legacy/mutationOptions.d.cts +68 -0
  41. package/build/legacy/mutationOptions.d.cts.map +1 -1
  42. package/build/legacy/mutationOptions.d.ts +68 -0
  43. package/build/legacy/mutationOptions.d.ts.map +1 -1
  44. package/build/legacy/mutationOptions.js.map +1 -1
  45. package/build/legacy/queryOptions.cjs.map +1 -1
  46. package/build/legacy/queryOptions.d.cts +198 -0
  47. package/build/legacy/queryOptions.d.cts.map +1 -1
  48. package/build/legacy/queryOptions.d.ts +198 -0
  49. package/build/legacy/queryOptions.d.ts.map +1 -1
  50. package/build/legacy/queryOptions.js.map +1 -1
  51. package/build/legacy/types.cjs.map +1 -1
  52. package/build/legacy/types.d.cts +228 -2
  53. package/build/legacy/types.d.cts.map +1 -1
  54. package/build/legacy/types.d.ts +228 -2
  55. package/build/legacy/types.d.ts.map +1 -1
  56. package/build/legacy/types.js.map +1 -1
  57. package/build/legacy/useInfiniteQuery.cjs.map +1 -1
  58. package/build/legacy/useInfiniteQuery.d.cts +120 -0
  59. package/build/legacy/useInfiniteQuery.d.cts.map +1 -1
  60. package/build/legacy/useInfiniteQuery.d.ts +120 -0
  61. package/build/legacy/useInfiniteQuery.d.ts.map +1 -1
  62. package/build/legacy/useInfiniteQuery.js.map +1 -1
  63. package/build/legacy/useIsFetching.cjs +34 -0
  64. package/build/legacy/useIsFetching.cjs.map +1 -1
  65. package/build/legacy/useIsFetching.d.cts +34 -0
  66. package/build/legacy/useIsFetching.d.cts.map +1 -1
  67. package/build/legacy/useIsFetching.d.ts +34 -0
  68. package/build/legacy/useIsFetching.d.ts.map +1 -1
  69. package/build/legacy/useIsFetching.js +34 -0
  70. package/build/legacy/useIsFetching.js.map +1 -1
  71. package/build/legacy/useMutation.cjs +170 -0
  72. package/build/legacy/useMutation.cjs.map +1 -1
  73. package/build/legacy/useMutation.d.cts +170 -0
  74. package/build/legacy/useMutation.d.cts.map +1 -1
  75. package/build/legacy/useMutation.d.ts +170 -0
  76. package/build/legacy/useMutation.d.ts.map +1 -1
  77. package/build/legacy/useMutation.js +170 -0
  78. package/build/legacy/useMutation.js.map +1 -1
  79. package/build/legacy/useMutationState.cjs +74 -0
  80. package/build/legacy/useMutationState.cjs.map +1 -1
  81. package/build/legacy/useMutationState.d.cts +74 -0
  82. package/build/legacy/useMutationState.d.cts.map +1 -1
  83. package/build/legacy/useMutationState.d.ts +74 -0
  84. package/build/legacy/useMutationState.d.ts.map +1 -1
  85. package/build/legacy/useMutationState.js +74 -0
  86. package/build/legacy/useMutationState.js.map +1 -1
  87. package/build/legacy/usePrefetchInfiniteQuery.cjs +44 -0
  88. package/build/legacy/usePrefetchInfiniteQuery.cjs.map +1 -1
  89. package/build/legacy/usePrefetchInfiniteQuery.d.cts +44 -0
  90. package/build/legacy/usePrefetchInfiniteQuery.d.cts.map +1 -1
  91. package/build/legacy/usePrefetchInfiniteQuery.d.ts +44 -0
  92. package/build/legacy/usePrefetchInfiniteQuery.d.ts.map +1 -1
  93. package/build/legacy/usePrefetchInfiniteQuery.js +44 -0
  94. package/build/legacy/usePrefetchInfiniteQuery.js.map +1 -1
  95. package/build/legacy/usePrefetchQuery.cjs +35 -0
  96. package/build/legacy/usePrefetchQuery.cjs.map +1 -1
  97. package/build/legacy/usePrefetchQuery.d.cts +35 -0
  98. package/build/legacy/usePrefetchQuery.d.cts.map +1 -1
  99. package/build/legacy/usePrefetchQuery.d.ts +35 -0
  100. package/build/legacy/usePrefetchQuery.d.ts.map +1 -1
  101. package/build/legacy/usePrefetchQuery.js +35 -0
  102. package/build/legacy/usePrefetchQuery.js.map +1 -1
  103. package/build/legacy/useQueries.cjs +50 -0
  104. package/build/legacy/useQueries.cjs.map +1 -1
  105. package/build/legacy/useQueries.d.cts +85 -2
  106. package/build/legacy/useQueries.d.cts.map +1 -1
  107. package/build/legacy/useQueries.d.ts +85 -2
  108. package/build/legacy/useQueries.d.ts.map +1 -1
  109. package/build/legacy/useQueries.js +50 -0
  110. package/build/legacy/useQueries.js.map +1 -1
  111. package/build/legacy/useQuery.cjs.map +1 -1
  112. package/build/legacy/useQuery.d.cts +186 -0
  113. package/build/legacy/useQuery.d.cts.map +1 -1
  114. package/build/legacy/useQuery.d.ts +186 -0
  115. package/build/legacy/useQuery.d.ts.map +1 -1
  116. package/build/legacy/useQuery.js.map +1 -1
  117. package/build/legacy/useSuspenseInfiniteQuery.cjs +56 -0
  118. package/build/legacy/useSuspenseInfiniteQuery.cjs.map +1 -1
  119. package/build/legacy/useSuspenseInfiniteQuery.d.cts +56 -0
  120. package/build/legacy/useSuspenseInfiniteQuery.d.cts.map +1 -1
  121. package/build/legacy/useSuspenseInfiniteQuery.d.ts +56 -0
  122. package/build/legacy/useSuspenseInfiniteQuery.d.ts.map +1 -1
  123. package/build/legacy/useSuspenseInfiniteQuery.js +56 -0
  124. package/build/legacy/useSuspenseInfiniteQuery.js.map +1 -1
  125. package/build/legacy/useSuspenseQueries.cjs.map +1 -1
  126. package/build/legacy/useSuspenseQueries.d.cts +196 -2
  127. package/build/legacy/useSuspenseQueries.d.cts.map +1 -1
  128. package/build/legacy/useSuspenseQueries.d.ts +196 -2
  129. package/build/legacy/useSuspenseQueries.d.ts.map +1 -1
  130. package/build/legacy/useSuspenseQueries.js.map +1 -1
  131. package/build/legacy/useSuspenseQuery.cjs +47 -0
  132. package/build/legacy/useSuspenseQuery.cjs.map +1 -1
  133. package/build/legacy/useSuspenseQuery.d.cts +47 -0
  134. package/build/legacy/useSuspenseQuery.d.cts.map +1 -1
  135. package/build/legacy/useSuspenseQuery.d.ts +47 -0
  136. package/build/legacy/useSuspenseQuery.d.ts.map +1 -1
  137. package/build/legacy/useSuspenseQuery.js +47 -0
  138. package/build/legacy/useSuspenseQuery.js.map +1 -1
  139. package/build/modern/HydrationBoundary.cjs +43 -0
  140. package/build/modern/HydrationBoundary.cjs.map +1 -1
  141. package/build/modern/HydrationBoundary.d.cts +61 -0
  142. package/build/modern/HydrationBoundary.d.cts.map +1 -1
  143. package/build/modern/HydrationBoundary.d.ts +61 -0
  144. package/build/modern/HydrationBoundary.d.ts.map +1 -1
  145. package/build/modern/HydrationBoundary.js +43 -0
  146. package/build/modern/HydrationBoundary.js.map +1 -1
  147. package/build/modern/IsRestoringProvider.cjs +11 -0
  148. package/build/modern/IsRestoringProvider.cjs.map +1 -1
  149. package/build/modern/IsRestoringProvider.d.cts +11 -0
  150. package/build/modern/IsRestoringProvider.d.cts.map +1 -1
  151. package/build/modern/IsRestoringProvider.d.ts +11 -0
  152. package/build/modern/IsRestoringProvider.d.ts.map +1 -1
  153. package/build/modern/IsRestoringProvider.js +11 -0
  154. package/build/modern/IsRestoringProvider.js.map +1 -1
  155. package/build/modern/QueryClientProvider.cjs +30 -0
  156. package/build/modern/QueryClientProvider.cjs.map +1 -1
  157. package/build/modern/QueryClientProvider.d.cts +41 -0
  158. package/build/modern/QueryClientProvider.d.cts.map +1 -1
  159. package/build/modern/QueryClientProvider.d.ts +41 -0
  160. package/build/modern/QueryClientProvider.d.ts.map +1 -1
  161. package/build/modern/QueryClientProvider.js +30 -0
  162. package/build/modern/QueryClientProvider.js.map +1 -1
  163. package/build/modern/QueryErrorResetBoundary.cjs +77 -0
  164. package/build/modern/QueryErrorResetBoundary.cjs.map +1 -1
  165. package/build/modern/QueryErrorResetBoundary.d.cts +108 -0
  166. package/build/modern/QueryErrorResetBoundary.d.cts.map +1 -1
  167. package/build/modern/QueryErrorResetBoundary.d.ts +108 -0
  168. package/build/modern/QueryErrorResetBoundary.d.ts.map +1 -1
  169. package/build/modern/QueryErrorResetBoundary.js +77 -0
  170. package/build/modern/QueryErrorResetBoundary.js.map +1 -1
  171. package/build/modern/infiniteQueryOptions.cjs.map +1 -1
  172. package/build/modern/infiniteQueryOptions.d.cts +187 -0
  173. package/build/modern/infiniteQueryOptions.d.cts.map +1 -1
  174. package/build/modern/infiniteQueryOptions.d.ts +187 -0
  175. package/build/modern/infiniteQueryOptions.d.ts.map +1 -1
  176. package/build/modern/infiniteQueryOptions.js.map +1 -1
  177. package/build/modern/mutationOptions.cjs.map +1 -1
  178. package/build/modern/mutationOptions.d.cts +68 -0
  179. package/build/modern/mutationOptions.d.cts.map +1 -1
  180. package/build/modern/mutationOptions.d.ts +68 -0
  181. package/build/modern/mutationOptions.d.ts.map +1 -1
  182. package/build/modern/mutationOptions.js.map +1 -1
  183. package/build/modern/queryOptions.cjs.map +1 -1
  184. package/build/modern/queryOptions.d.cts +198 -0
  185. package/build/modern/queryOptions.d.cts.map +1 -1
  186. package/build/modern/queryOptions.d.ts +198 -0
  187. package/build/modern/queryOptions.d.ts.map +1 -1
  188. package/build/modern/queryOptions.js.map +1 -1
  189. package/build/modern/types.cjs.map +1 -1
  190. package/build/modern/types.d.cts +228 -2
  191. package/build/modern/types.d.cts.map +1 -1
  192. package/build/modern/types.d.ts +228 -2
  193. package/build/modern/types.d.ts.map +1 -1
  194. package/build/modern/types.js.map +1 -1
  195. package/build/modern/useInfiniteQuery.cjs.map +1 -1
  196. package/build/modern/useInfiniteQuery.d.cts +120 -0
  197. package/build/modern/useInfiniteQuery.d.cts.map +1 -1
  198. package/build/modern/useInfiniteQuery.d.ts +120 -0
  199. package/build/modern/useInfiniteQuery.d.ts.map +1 -1
  200. package/build/modern/useInfiniteQuery.js.map +1 -1
  201. package/build/modern/useIsFetching.cjs +34 -0
  202. package/build/modern/useIsFetching.cjs.map +1 -1
  203. package/build/modern/useIsFetching.d.cts +34 -0
  204. package/build/modern/useIsFetching.d.cts.map +1 -1
  205. package/build/modern/useIsFetching.d.ts +34 -0
  206. package/build/modern/useIsFetching.d.ts.map +1 -1
  207. package/build/modern/useIsFetching.js +34 -0
  208. package/build/modern/useIsFetching.js.map +1 -1
  209. package/build/modern/useMutation.cjs +170 -0
  210. package/build/modern/useMutation.cjs.map +1 -1
  211. package/build/modern/useMutation.d.cts +170 -0
  212. package/build/modern/useMutation.d.cts.map +1 -1
  213. package/build/modern/useMutation.d.ts +170 -0
  214. package/build/modern/useMutation.d.ts.map +1 -1
  215. package/build/modern/useMutation.js +170 -0
  216. package/build/modern/useMutation.js.map +1 -1
  217. package/build/modern/useMutationState.cjs +74 -0
  218. package/build/modern/useMutationState.cjs.map +1 -1
  219. package/build/modern/useMutationState.d.cts +74 -0
  220. package/build/modern/useMutationState.d.cts.map +1 -1
  221. package/build/modern/useMutationState.d.ts +74 -0
  222. package/build/modern/useMutationState.d.ts.map +1 -1
  223. package/build/modern/useMutationState.js +74 -0
  224. package/build/modern/useMutationState.js.map +1 -1
  225. package/build/modern/usePrefetchInfiniteQuery.cjs +44 -0
  226. package/build/modern/usePrefetchInfiniteQuery.cjs.map +1 -1
  227. package/build/modern/usePrefetchInfiniteQuery.d.cts +44 -0
  228. package/build/modern/usePrefetchInfiniteQuery.d.cts.map +1 -1
  229. package/build/modern/usePrefetchInfiniteQuery.d.ts +44 -0
  230. package/build/modern/usePrefetchInfiniteQuery.d.ts.map +1 -1
  231. package/build/modern/usePrefetchInfiniteQuery.js +44 -0
  232. package/build/modern/usePrefetchInfiniteQuery.js.map +1 -1
  233. package/build/modern/usePrefetchQuery.cjs +35 -0
  234. package/build/modern/usePrefetchQuery.cjs.map +1 -1
  235. package/build/modern/usePrefetchQuery.d.cts +35 -0
  236. package/build/modern/usePrefetchQuery.d.cts.map +1 -1
  237. package/build/modern/usePrefetchQuery.d.ts +35 -0
  238. package/build/modern/usePrefetchQuery.d.ts.map +1 -1
  239. package/build/modern/usePrefetchQuery.js +35 -0
  240. package/build/modern/usePrefetchQuery.js.map +1 -1
  241. package/build/modern/useQueries.cjs +50 -0
  242. package/build/modern/useQueries.cjs.map +1 -1
  243. package/build/modern/useQueries.d.cts +85 -2
  244. package/build/modern/useQueries.d.cts.map +1 -1
  245. package/build/modern/useQueries.d.ts +85 -2
  246. package/build/modern/useQueries.d.ts.map +1 -1
  247. package/build/modern/useQueries.js +50 -0
  248. package/build/modern/useQueries.js.map +1 -1
  249. package/build/modern/useQuery.cjs.map +1 -1
  250. package/build/modern/useQuery.d.cts +186 -0
  251. package/build/modern/useQuery.d.cts.map +1 -1
  252. package/build/modern/useQuery.d.ts +186 -0
  253. package/build/modern/useQuery.d.ts.map +1 -1
  254. package/build/modern/useQuery.js.map +1 -1
  255. package/build/modern/useSuspenseInfiniteQuery.cjs +56 -0
  256. package/build/modern/useSuspenseInfiniteQuery.cjs.map +1 -1
  257. package/build/modern/useSuspenseInfiniteQuery.d.cts +56 -0
  258. package/build/modern/useSuspenseInfiniteQuery.d.cts.map +1 -1
  259. package/build/modern/useSuspenseInfiniteQuery.d.ts +56 -0
  260. package/build/modern/useSuspenseInfiniteQuery.d.ts.map +1 -1
  261. package/build/modern/useSuspenseInfiniteQuery.js +56 -0
  262. package/build/modern/useSuspenseInfiniteQuery.js.map +1 -1
  263. package/build/modern/useSuspenseQueries.cjs.map +1 -1
  264. package/build/modern/useSuspenseQueries.d.cts +196 -2
  265. package/build/modern/useSuspenseQueries.d.cts.map +1 -1
  266. package/build/modern/useSuspenseQueries.d.ts +196 -2
  267. package/build/modern/useSuspenseQueries.d.ts.map +1 -1
  268. package/build/modern/useSuspenseQueries.js.map +1 -1
  269. package/build/modern/useSuspenseQuery.cjs +47 -0
  270. package/build/modern/useSuspenseQuery.cjs.map +1 -1
  271. package/build/modern/useSuspenseQuery.d.cts +47 -0
  272. package/build/modern/useSuspenseQuery.d.cts.map +1 -1
  273. package/build/modern/useSuspenseQuery.d.ts +47 -0
  274. package/build/modern/useSuspenseQuery.d.ts.map +1 -1
  275. package/build/modern/useSuspenseQuery.js +47 -0
  276. package/build/modern/useSuspenseQuery.js.map +1 -1
  277. package/package.json +3 -3
  278. package/src/HydrationBoundary.tsx +61 -0
  279. package/src/IsRestoringProvider.ts +12 -0
  280. package/src/QueryClientProvider.tsx +41 -0
  281. package/src/QueryErrorResetBoundary.tsx +111 -0
  282. package/src/infiniteQueryOptions.ts +187 -0
  283. package/src/mutationOptions.ts +68 -0
  284. package/src/queryOptions.ts +198 -0
  285. package/src/types.ts +228 -2
  286. package/src/useInfiniteQuery.ts +120 -0
  287. package/src/useIsFetching.ts +34 -0
  288. package/src/useMutation.ts +170 -0
  289. package/src/useMutationState.ts +74 -0
  290. package/src/usePrefetchInfiniteQuery.tsx +44 -0
  291. package/src/usePrefetchQuery.tsx +35 -0
  292. package/src/useQueries.ts +85 -2
  293. package/src/useQuery.ts +186 -0
  294. package/src/useSuspenseInfiniteQuery.ts +56 -0
  295. package/src/useSuspenseQueries.ts +196 -2
  296. package/src/useSuspenseQuery.ts +47 -0
@@ -11,6 +11,17 @@ import type {
11
11
 
12
12
  import type { UseInfiniteQueryOptions } from './types'
13
13
 
14
+ /**
15
+ * The options accepted by the `infiniteQueryOptions` overload selected when no `initialData` is set — `data`
16
+ * may be `undefined` while the query is `pending`.
17
+ *
18
+ * @template TQueryFnData - The type of a single page, as your `queryFn` resolves it.
19
+ * @template TError - The type of errors your `queryFn` may throw.
20
+ * @template TData - The type `data` ends up as after `select` runs — defaults to `InfiniteData<TQueryFnData>`,
21
+ * the shape of all fetched pages plus their page params.
22
+ * @template TQueryKey - The type of your `queryKey`.
23
+ * @template TPageParam - The type of the parameter passed to `queryFn` to fetch a given page.
24
+ */
14
25
  export type UndefinedInitialDataInfiniteOptions<
15
26
  TQueryFnData,
16
27
  TError = DefaultError,
@@ -24,6 +35,13 @@ export type UndefinedInitialDataInfiniteOptions<
24
35
  TQueryKey,
25
36
  TPageParam
26
37
  > & {
38
+ /**
39
+ * If set, this value will be used as the initial data for the query cache (as long as the query hasn't been
40
+ * created or cached yet). If set to a function, the function will be called **once** during the shared/root
41
+ * query initialization, and be expected to synchronously return the initial data. Initial data is
42
+ * considered stale by default unless a `staleTime` has been set. `initialData` **is persisted** to the
43
+ * cache.
44
+ */
27
45
  initialData?:
28
46
  | undefined
29
47
  | NonUndefinedGuard<InfiniteData<TQueryFnData, TPageParam>>
@@ -32,6 +50,18 @@ export type UndefinedInitialDataInfiniteOptions<
32
50
  >
33
51
  }
34
52
 
53
+ /**
54
+ * The options accepted by the `infiniteQueryOptions` overload selected when no `initialData` is set and
55
+ * `queryFn` is not `skipToken` — same as {@link UndefinedInitialDataInfiniteOptions}, but `queryFn` may not be
56
+ * `skipToken`.
57
+ *
58
+ * @template TQueryFnData - The type of a single page, as your `queryFn` resolves it.
59
+ * @template TError - The type of errors your `queryFn` may throw.
60
+ * @template TData - The type `data` ends up as after `select` runs — defaults to `InfiniteData<TQueryFnData>`,
61
+ * the shape of all fetched pages plus their page params.
62
+ * @template TQueryKey - The type of your `queryKey`.
63
+ * @template TPageParam - The type of the parameter passed to `queryFn` to fetch a given page.
64
+ */
35
65
  export type UnusedSkipTokenInfiniteOptions<
36
66
  TQueryFnData,
37
67
  TError = DefaultError,
@@ -42,6 +72,10 @@ export type UnusedSkipTokenInfiniteOptions<
42
72
  UseInfiniteQueryOptions<TQueryFnData, TError, TData, TQueryKey, TPageParam>,
43
73
  'queryFn'
44
74
  > & {
75
+ /**
76
+ * `skipToken` is not allowed as a value here — this overload is selected when no `initialData` is set. If
77
+ * you don't intend to run the query yet, omit `queryFn` or use a default query function instead.
78
+ */
45
79
  queryFn?: Exclude<
46
80
  UseInfiniteQueryOptions<
47
81
  TQueryFnData,
@@ -54,6 +88,17 @@ export type UnusedSkipTokenInfiniteOptions<
54
88
  >
55
89
  }
56
90
 
91
+ /**
92
+ * The options accepted by the `infiniteQueryOptions` overload selected when `initialData` is set — `data` is
93
+ * never `undefined`.
94
+ *
95
+ * @template TQueryFnData - The type of a single page, as your `queryFn` resolves it.
96
+ * @template TError - The type of errors your `queryFn` may throw.
97
+ * @template TData - The type `data` ends up as after `select` runs — defaults to `InfiniteData<TQueryFnData>`,
98
+ * the shape of all fetched pages plus their page params.
99
+ * @template TQueryKey - The type of your `queryKey`.
100
+ * @template TPageParam - The type of the parameter passed to `queryFn` to fetch a given page.
101
+ */
57
102
  export type DefinedInitialDataInfiniteOptions<
58
103
  TQueryFnData,
59
104
  TError = DefaultError,
@@ -67,12 +112,48 @@ export type DefinedInitialDataInfiniteOptions<
67
112
  TQueryKey,
68
113
  TPageParam
69
114
  > & {
115
+ /**
116
+ * If set, this value will be used as the initial data for the query cache (as long as the query hasn't been
117
+ * created or cached yet). If set to a function, the function will be called **once** during the shared/root
118
+ * query initialization, and be expected to synchronously return the initial data. Initial data is
119
+ * considered stale by default unless a `staleTime` has been set. `initialData` **is persisted** to the
120
+ * cache.
121
+ */
70
122
  initialData:
71
123
  | NonUndefinedGuard<InfiniteData<TQueryFnData, TPageParam>>
72
124
  | (() => NonUndefinedGuard<InfiniteData<TQueryFnData, TPageParam>>)
73
125
  | undefined
74
126
  }
75
127
 
128
+ /**
129
+ * You can generally pass everything to `infiniteQueryOptions` that you can also pass to `useInfiniteQuery`.
130
+ * These options can be shared across hooks and imperative APIs such as `queryClient.infiniteQuery`.
131
+ * `options.queryKey` is required and is the query key to generate options for.
132
+ *
133
+ * This overload is selected when `initialData` is set.
134
+ *
135
+ * @see {@link useInfiniteQuery} to run an infinite query with these options.
136
+ * @param options - The {@link DefinedInitialDataInfiniteOptions} to use — everything you can pass to `useInfiniteQuery`, with `initialData` set.
137
+ * @returns The same options object, typed so that `queryKey` carries the inferred data type.
138
+ *
139
+ * @example
140
+ * ```tsx
141
+ * import { infiniteQueryOptions, useInfiniteQuery } from '@tanstack/preact-query'
142
+ *
143
+ * export const projectsOptions = infiniteQueryOptions({
144
+ * queryKey: ['projects'],
145
+ * queryFn: ({ pageParam }) => fetchProjects(pageParam),
146
+ * initialPageParam: 0,
147
+ * getNextPageParam: (lastPage) => lastPage.nextId,
148
+ * initialData: { pages: [], pageParams: [] },
149
+ * })
150
+ *
151
+ * function Projects() {
152
+ * const { data } = useInfiniteQuery(projectsOptions)
153
+ * return <>{data.pages.map((page) => page.projects.map((p) => <p key={p.id}>{p.name}</p>))}</>
154
+ * }
155
+ * ```
156
+ */
76
157
  export function infiniteQueryOptions<
77
158
  TQueryFnData,
78
159
  TError = DefaultError,
@@ -96,6 +177,59 @@ export function infiniteQueryOptions<
96
177
  > &
97
178
  QueryKeyWithDataTag<TQueryKey, InfiniteData<TQueryFnData>, TError>
98
179
 
180
+ /**
181
+ * You can generally pass everything to `infiniteQueryOptions` that you can also pass to `useInfiniteQuery`.
182
+ * These options can be shared across hooks and imperative APIs such as `queryClient.infiniteQuery`.
183
+ * `options.queryKey` is required and is the query key to generate options for.
184
+ *
185
+ * @returns The same options object, typed so that `queryKey` carries the inferred data type.
186
+ *
187
+ * @example
188
+ * ```tsx
189
+ * import { infiniteQueryOptions } from '@tanstack/preact-query'
190
+ *
191
+ * export const projectsOptions = infiniteQueryOptions({
192
+ * queryKey: ['projects'],
193
+ * queryFn: ({ pageParam }) => fetchProjects(pageParam),
194
+ * initialPageParam: 0,
195
+ * getNextPageParam: (lastPage) => lastPage.nextId,
196
+ * })
197
+ * ```
198
+ *
199
+ * @example
200
+ * A parameterized factory, reused across a hook and an imperative call with the same cache entry:
201
+ * ```tsx
202
+ * import {
203
+ * infiniteQueryOptions,
204
+ * noop,
205
+ * useInfiniteQuery,
206
+ * } from '@tanstack/preact-query'
207
+ *
208
+ * export const commentsOptions = (postId: string) =>
209
+ * infiniteQueryOptions({
210
+ * queryKey: ['post', postId, 'comments'],
211
+ * queryFn: ({ pageParam }) => fetchComments(postId, pageParam),
212
+ * initialPageParam: 0,
213
+ * getNextPageParam: (lastPage) => lastPage.nextId,
214
+ * })
215
+ *
216
+ * function Comments({ postId }: { postId: string }) {
217
+ * const result = useInfiniteQuery(commentsOptions(postId))
218
+ * if (!result.isSuccess) return 'Loading...'
219
+ * return (
220
+ * <>
221
+ * {result.data.pages.map((page) => page.comments.map((c) => <p key={c.id}>{c.text}</p>))}
222
+ * </>
223
+ * )
224
+ * }
225
+ *
226
+ * // Elsewhere, e.g. to warm the cache before rendering `<Comments>`:
227
+ * queryClient.infiniteQuery(commentsOptions(postId)).catch(noop)
228
+ * ```
229
+ *
230
+ * @see {@link useInfiniteQuery} to run an infinite query with these options.
231
+ * @param options - The {@link UnusedSkipTokenInfiniteOptions} to use — everything you can pass to `useInfiniteQuery`.
232
+ */
99
233
  export function infiniteQueryOptions<
100
234
  TQueryFnData,
101
235
  TError = DefaultError,
@@ -119,6 +253,59 @@ export function infiniteQueryOptions<
119
253
  > &
120
254
  QueryKeyWithDataTag<TQueryKey, InfiniteData<TQueryFnData>, TError>
121
255
 
256
+ /**
257
+ * You can generally pass everything to `infiniteQueryOptions` that you can also pass to `useInfiniteQuery`.
258
+ * These options can be shared across hooks and imperative APIs such as `queryClient.infiniteQuery`.
259
+ * `options.queryKey` is required and is the query key to generate options for.
260
+ *
261
+ * @returns The same options object, typed so that `queryKey` carries the inferred data type.
262
+ *
263
+ * @example
264
+ * ```tsx
265
+ * import { infiniteQueryOptions } from '@tanstack/preact-query'
266
+ *
267
+ * export const projectsOptions = infiniteQueryOptions({
268
+ * queryKey: ['projects'],
269
+ * queryFn: ({ pageParam }) => fetchProjects(pageParam),
270
+ * initialPageParam: 0,
271
+ * getNextPageParam: (lastPage) => lastPage.nextId,
272
+ * })
273
+ * ```
274
+ *
275
+ * @example
276
+ * A parameterized factory, reused across a hook and an imperative call with the same cache entry:
277
+ * ```tsx
278
+ * import {
279
+ * infiniteQueryOptions,
280
+ * noop,
281
+ * useInfiniteQuery,
282
+ * } from '@tanstack/preact-query'
283
+ *
284
+ * export const commentsOptions = (postId: string) =>
285
+ * infiniteQueryOptions({
286
+ * queryKey: ['post', postId, 'comments'],
287
+ * queryFn: ({ pageParam }) => fetchComments(postId, pageParam),
288
+ * initialPageParam: 0,
289
+ * getNextPageParam: (lastPage) => lastPage.nextId,
290
+ * })
291
+ *
292
+ * function Comments({ postId }: { postId: string }) {
293
+ * const result = useInfiniteQuery(commentsOptions(postId))
294
+ * if (!result.isSuccess) return 'Loading...'
295
+ * return (
296
+ * <>
297
+ * {result.data.pages.map((page) => page.comments.map((c) => <p key={c.id}>{c.text}</p>))}
298
+ * </>
299
+ * )
300
+ * }
301
+ *
302
+ * // Elsewhere, e.g. to warm the cache before rendering `<Comments>`:
303
+ * queryClient.infiniteQuery(commentsOptions(postId)).catch(noop)
304
+ * ```
305
+ *
306
+ * @see {@link useInfiniteQuery} to run an infinite query with these options.
307
+ * @param options - The {@link UndefinedInitialDataInfiniteOptions} to use — everything you can pass to `useInfiniteQuery`.
308
+ */
122
309
  export function infiniteQueryOptions<
123
310
  TQueryFnData,
124
311
  TError = DefaultError,
@@ -2,6 +2,50 @@ import type { DefaultError, WithRequired } from '@tanstack/query-core'
2
2
 
3
3
  import type { UseMutationOptions } from './types'
4
4
 
5
+ /**
6
+ * You can generally pass everything to `mutationOptions` that you can also pass to `useMutation`. A
7
+ * `mutationKey` is required on this overload so the mutation can be looked up later, e.g. with
8
+ * `useMutationState`.
9
+ *
10
+ * @see {@link useMutation} to run the mutation these options describe.
11
+ * @param options - The mutation options to use, identical to what you'd pass to `useMutation`, with a
12
+ * required `mutationKey`.
13
+ * @returns The same options object, unchanged.
14
+ *
15
+ * @example
16
+ * ```tsx
17
+ * import { mutationOptions, useMutation } from '@tanstack/preact-query'
18
+ *
19
+ * export const createPostOptions = mutationOptions({
20
+ * mutationKey: ['posts', 'create'],
21
+ * mutationFn: createPost,
22
+ * })
23
+ *
24
+ * function CreatePost() {
25
+ * const mutation = useMutation(createPostOptions)
26
+ * return <button onClick={() => mutation.mutate({ title: 'Hello' })}>Create</button>
27
+ * }
28
+ * ```
29
+ *
30
+ * @example
31
+ * Looking the mutation up elsewhere via its `mutationKey`, e.g. for a global "saving…" indicator:
32
+ * ```tsx
33
+ * import { mutationOptions, useMutationState } from '@tanstack/preact-query'
34
+ *
35
+ * const createPostOptions = mutationOptions({
36
+ * mutationKey: ['posts', 'create'],
37
+ * mutationFn: createPost,
38
+ * })
39
+ *
40
+ * function SavingIndicator() {
41
+ * const isCreatingPost = useMutationState({
42
+ * filters: { mutationKey: createPostOptions.mutationKey, status: 'pending' },
43
+ * }).length > 0
44
+ *
45
+ * return isCreatingPost ? <span>Saving…</span> : null
46
+ * }
47
+ * ```
48
+ */
5
49
  export function mutationOptions<
6
50
  TData = unknown,
7
51
  TError = DefaultError,
@@ -16,6 +60,30 @@ export function mutationOptions<
16
60
  UseMutationOptions<TData, TError, TVariables, TOnMutateResult>,
17
61
  'mutationKey'
18
62
  >
63
+ /**
64
+ * You can generally pass everything to `mutationOptions` that you can also pass to `useMutation`. No
65
+ * `mutationKey` is required on this overload — use this when you don't need to look the mutation up later
66
+ * (e.g. with `useMutationState`).
67
+ *
68
+ * @see {@link useMutation} to run the mutation these options describe.
69
+ * @param options - The mutation options to use, identical to what you'd pass to `useMutation`, without a
70
+ * `mutationKey`.
71
+ * @returns The same options object, unchanged.
72
+ *
73
+ * @example
74
+ * ```tsx
75
+ * import { mutationOptions, useMutation } from '@tanstack/preact-query'
76
+ *
77
+ * export const createPostOptions = mutationOptions({
78
+ * mutationFn: createPost,
79
+ * })
80
+ *
81
+ * function CreatePost() {
82
+ * const mutation = useMutation(createPostOptions)
83
+ * return <button onClick={() => mutation.mutate({ title: 'Hello' })}>Create</button>
84
+ * }
85
+ * ```
86
+ */
19
87
  export function mutationOptions<
20
88
  TData = unknown,
21
89
  TError = DefaultError,
@@ -11,18 +11,43 @@ import type {
11
11
 
12
12
  import type { UseQueryOptions } from './types'
13
13
 
14
+ /**
15
+ * The options accepted by the `queryOptions` overload selected when no `initialData` is set — `data` may be
16
+ * `undefined` while the query is `pending`.
17
+ *
18
+ * @template TQueryFnData - The type your `queryFn` resolves to.
19
+ * @template TError - The type of errors your `queryFn` may throw.
20
+ * @template TData - The type `data` ends up as after `select` runs.
21
+ * @template TQueryKey - The type of your `queryKey`.
22
+ */
14
23
  export type UndefinedInitialDataOptions<
15
24
  TQueryFnData = unknown,
16
25
  TError = DefaultError,
17
26
  TData = TQueryFnData,
18
27
  TQueryKey extends QueryKey = QueryKey,
19
28
  > = UseQueryOptions<TQueryFnData, TError, TData, TQueryKey> & {
29
+ /**
30
+ * If set, this value will be used as the initial data for the query cache (as long as the query hasn't been
31
+ * created or cached yet). If set to a function, the function will be called **once** during the shared/root
32
+ * query initialization, and be expected to synchronously return the initial data. Initial data is
33
+ * considered stale by default unless a `staleTime` has been set. `initialData` **is persisted** to the
34
+ * cache.
35
+ */
20
36
  initialData?:
21
37
  | undefined
22
38
  | InitialDataFunction<NonUndefinedGuard<TQueryFnData>>
23
39
  | NonUndefinedGuard<TQueryFnData>
24
40
  }
25
41
 
42
+ /**
43
+ * The options accepted by the `queryOptions` overload selected when no `initialData` is set and `queryFn` is
44
+ * not `skipToken` — same as {@link UndefinedInitialDataOptions}, but `queryFn` may not be `skipToken`.
45
+ *
46
+ * @template TQueryFnData - The type your `queryFn` resolves to.
47
+ * @template TError - The type of errors your `queryFn` may throw.
48
+ * @template TData - The type `data` ends up as after `select` runs.
49
+ * @template TQueryKey - The type of your `queryKey`.
50
+ */
26
51
  export type UnusedSkipTokenOptions<
27
52
  TQueryFnData = unknown,
28
53
  TError = DefaultError,
@@ -32,24 +57,77 @@ export type UnusedSkipTokenOptions<
32
57
  UseQueryOptions<TQueryFnData, TError, TData, TQueryKey>,
33
58
  'queryFn'
34
59
  > & {
60
+ /**
61
+ * `skipToken` is not allowed as a value here — this overload is selected when no `initialData` is set. If
62
+ * you don't intend to run the query yet, omit `queryFn` or use a default query function instead.
63
+ */
35
64
  queryFn?: Exclude<
36
65
  UseQueryOptions<TQueryFnData, TError, TData, TQueryKey>['queryFn'],
37
66
  SkipToken | undefined
38
67
  >
39
68
  }
40
69
 
70
+ /**
71
+ * The options accepted by the `queryOptions` overload selected when `initialData` is set — `data` is never
72
+ * `undefined`.
73
+ *
74
+ * @template TQueryFnData - The type your `queryFn` resolves to.
75
+ * @template TError - The type of errors your `queryFn` may throw.
76
+ * @template TData - The type `data` ends up as after `select` runs.
77
+ * @template TQueryKey - The type of your `queryKey`.
78
+ */
41
79
  export type DefinedInitialDataOptions<
42
80
  TQueryFnData = unknown,
43
81
  TError = DefaultError,
44
82
  TData = TQueryFnData,
45
83
  TQueryKey extends QueryKey = QueryKey,
46
84
  > = Omit<UseQueryOptions<TQueryFnData, TError, TData, TQueryKey>, 'queryFn'> & {
85
+ /**
86
+ * If set, this value will be used as the initial data for the query cache (as long as the query hasn't been
87
+ * created or cached yet). If set to a function, the function will be called **once** during the shared/root
88
+ * query initialization, and be expected to synchronously return the initial data. Initial data is
89
+ * considered stale by default unless a `staleTime` has been set. `initialData` **is persisted** to the
90
+ * cache.
91
+ */
47
92
  initialData:
48
93
  | NonUndefinedGuard<TQueryFnData>
49
94
  | (() => NonUndefinedGuard<TQueryFnData>)
95
+ /**
96
+ * Optional here, but omitting it is only safe when no fetch will be attempted — for example with
97
+ * `enabled: false`, or when a default query function has been defined. Otherwise, an enabled query with no
98
+ * `queryFn` still tries to fetch and fails with a "Missing queryFn" error; `initialData` does not prevent this.
99
+ */
50
100
  queryFn?: QueryFunction<TQueryFnData, TQueryKey>
51
101
  }
52
102
 
103
+ /**
104
+ * You can generally pass everything to `queryOptions` that you can also pass to `useQuery`. These options can
105
+ * be shared across hooks and imperative APIs such as `queryClient.query`. `options.queryKey` is required and
106
+ * is the query key to generate options for.
107
+ *
108
+ * This overload is selected when `initialData` is set, so the resulting `data` is never `undefined`.
109
+ *
110
+ * @see {@link useQuery} to run a query with these options.
111
+ * @param options - The {@link DefinedInitialDataOptions} to use — everything you can pass to `useQuery`, with `initialData` set.
112
+ * @returns The same options object, typed so that `queryKey` carries the inferred data type.
113
+ *
114
+ * @example
115
+ * ```tsx
116
+ * import { queryOptions, useQuery } from '@tanstack/preact-query'
117
+ *
118
+ * export const postsOptions = queryOptions({
119
+ * queryKey: ['posts'],
120
+ * queryFn: fetchPosts,
121
+ * initialData: [],
122
+ * })
123
+ *
124
+ * function Posts() {
125
+ * // `data` is `Post[]`, never `undefined`, thanks to `initialData`.
126
+ * const { data } = useQuery(postsOptions)
127
+ * return <>{data.map((post) => <p key={post.id}>{post.title}</p>)}</>
128
+ * }
129
+ * ```
130
+ */
53
131
  export function queryOptions<
54
132
  TQueryFnData = unknown,
55
133
  TError = DefaultError,
@@ -60,6 +138,66 @@ export function queryOptions<
60
138
  ): DefinedInitialDataOptions<TQueryFnData, TError, TData, TQueryKey> &
61
139
  QueryKeyWithDataTag<TQueryKey, TQueryFnData, TError>
62
140
 
141
+ /**
142
+ * You can generally pass everything to `queryOptions` that you can also pass to `useQuery`. These options can
143
+ * be shared across hooks and imperative APIs such as `queryClient.query`. `options.queryKey` is required and
144
+ * is the query key to generate options for.
145
+ *
146
+ * @see {@link useQuery} to run a query with these options.
147
+ * @param options - The {@link UnusedSkipTokenOptions} to use — everything you can pass to `useQuery`.
148
+ * @returns The same options object, typed so that `queryKey` carries the inferred data type.
149
+ *
150
+ * @example
151
+ * ```tsx
152
+ * import { queryOptions } from '@tanstack/preact-query'
153
+ *
154
+ * export const postsOptions = queryOptions({
155
+ * queryKey: ['posts'],
156
+ * queryFn: fetchPosts,
157
+ * })
158
+ * ```
159
+ *
160
+ * @example
161
+ * A parameterized factory, reused across a hook and an imperative call with the same cache entry:
162
+ * ```tsx
163
+ * import { noop, queryOptions, useQuery } from '@tanstack/preact-query'
164
+ *
165
+ * export const postOptions = (id: string) =>
166
+ * queryOptions({
167
+ * queryKey: ['post', id],
168
+ * queryFn: () => fetchPost(id),
169
+ * })
170
+ *
171
+ * function Post({ id }: { id: string }) {
172
+ * const { data } = useQuery(postOptions(id))
173
+ * return <h1>{data?.title}</h1>
174
+ * }
175
+ *
176
+ * // Elsewhere, e.g. to warm the cache before rendering `<Post>`:
177
+ * queryClient.query(postOptions(id)).catch(noop)
178
+ * ```
179
+ *
180
+ * @example
181
+ * The same options object works with every API that accepts query options:
182
+ * ```tsx
183
+ * import {
184
+ * noop,
185
+ * queryOptions,
186
+ * useQuery,
187
+ * useSuspenseQuery,
188
+ * } from '@tanstack/preact-query'
189
+ *
190
+ * const todosOptions = queryOptions({
191
+ * queryKey: ['todos'],
192
+ * queryFn: fetchTodos,
193
+ * })
194
+ *
195
+ * useQuery(todosOptions)
196
+ * useSuspenseQuery(todosOptions)
197
+ * queryClient.query(todosOptions).catch(noop)
198
+ * queryClient.getQueryData(todosOptions.queryKey) // typed as Array<Todo> | undefined
199
+ * ```
200
+ */
63
201
  export function queryOptions<
64
202
  TQueryFnData = unknown,
65
203
  TError = DefaultError,
@@ -70,6 +208,66 @@ export function queryOptions<
70
208
  ): UnusedSkipTokenOptions<TQueryFnData, TError, TData, TQueryKey> &
71
209
  QueryKeyWithDataTag<TQueryKey, TQueryFnData, TError>
72
210
 
211
+ /**
212
+ * You can generally pass everything to `queryOptions` that you can also pass to `useQuery`. These options can
213
+ * be shared across hooks and imperative APIs such as `queryClient.query`. `options.queryKey` is required and
214
+ * is the query key to generate options for.
215
+ *
216
+ * @see {@link useQuery} to run a query with these options.
217
+ * @param options - The {@link UndefinedInitialDataOptions} to use — everything you can pass to `useQuery`.
218
+ * @returns The same options object, typed so that `queryKey` carries the inferred data type.
219
+ *
220
+ * @example
221
+ * ```tsx
222
+ * import { queryOptions } from '@tanstack/preact-query'
223
+ *
224
+ * export const postsOptions = queryOptions({
225
+ * queryKey: ['posts'],
226
+ * queryFn: fetchPosts,
227
+ * })
228
+ * ```
229
+ *
230
+ * @example
231
+ * A parameterized factory, reused across a hook and an imperative call with the same cache entry:
232
+ * ```tsx
233
+ * import { noop, queryOptions, useQuery } from '@tanstack/preact-query'
234
+ *
235
+ * export const postOptions = (id: string) =>
236
+ * queryOptions({
237
+ * queryKey: ['post', id],
238
+ * queryFn: () => fetchPost(id),
239
+ * })
240
+ *
241
+ * function Post({ id }: { id: string }) {
242
+ * const { data } = useQuery(postOptions(id))
243
+ * return <h1>{data?.title}</h1>
244
+ * }
245
+ *
246
+ * // Elsewhere, e.g. to warm the cache before rendering `<Post>`:
247
+ * queryClient.query(postOptions(id)).catch(noop)
248
+ * ```
249
+ *
250
+ * @example
251
+ * The same options object works with every API that accepts query options:
252
+ * ```tsx
253
+ * import {
254
+ * noop,
255
+ * queryOptions,
256
+ * useQuery,
257
+ * useSuspenseQuery,
258
+ * } from '@tanstack/preact-query'
259
+ *
260
+ * const todosOptions = queryOptions({
261
+ * queryKey: ['todos'],
262
+ * queryFn: fetchTodos,
263
+ * })
264
+ *
265
+ * useQuery(todosOptions)
266
+ * useSuspenseQuery(todosOptions)
267
+ * queryClient.query(todosOptions).catch(noop)
268
+ * queryClient.getQueryData(todosOptions.queryKey) // typed as Array<Todo> | undefined
269
+ * ```
270
+ */
73
271
  export function queryOptions<
74
272
  TQueryFnData = unknown,
75
273
  TError = DefaultError,