@tanstack/react-query 5.102.8 → 5.103.0

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 (298) hide show
  1. package/build/legacy/HydrationBoundary.cjs +44 -1
  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 +44 -1
  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 +76 -0
  26. package/build/legacy/QueryErrorResetBoundary.cjs.map +1 -1
  27. package/build/legacy/QueryErrorResetBoundary.d.cts +77 -0
  28. package/build/legacy/QueryErrorResetBoundary.d.cts.map +1 -1
  29. package/build/legacy/QueryErrorResetBoundary.d.ts +77 -0
  30. package/build/legacy/QueryErrorResetBoundary.d.ts.map +1 -1
  31. package/build/legacy/QueryErrorResetBoundary.js +76 -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 +173 -0
  35. package/build/legacy/infiniteQueryOptions.d.cts.map +1 -1
  36. package/build/legacy/infiniteQueryOptions.d.ts +173 -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 +55 -0
  41. package/build/legacy/mutationOptions.d.cts.map +1 -1
  42. package/build/legacy/mutationOptions.d.ts +55 -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 +175 -0
  47. package/build/legacy/queryOptions.d.cts.map +1 -1
  48. package/build/legacy/queryOptions.d.ts +175 -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 +292 -0
  59. package/build/legacy/useInfiniteQuery.d.cts.map +1 -1
  60. package/build/legacy/useInfiniteQuery.d.ts +292 -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 +36 -0
  64. package/build/legacy/useIsFetching.cjs.map +1 -1
  65. package/build/legacy/useIsFetching.d.cts +36 -0
  66. package/build/legacy/useIsFetching.d.cts.map +1 -1
  67. package/build/legacy/useIsFetching.d.ts +36 -0
  68. package/build/legacy/useIsFetching.d.ts.map +1 -1
  69. package/build/legacy/useIsFetching.js +36 -0
  70. package/build/legacy/useIsFetching.js.map +1 -1
  71. package/build/legacy/useMutation.cjs +172 -0
  72. package/build/legacy/useMutation.cjs.map +1 -1
  73. package/build/legacy/useMutation.d.cts +172 -0
  74. package/build/legacy/useMutation.d.cts.map +1 -1
  75. package/build/legacy/useMutation.d.ts +172 -0
  76. package/build/legacy/useMutation.d.ts.map +1 -1
  77. package/build/legacy/useMutation.js +172 -0
  78. package/build/legacy/useMutation.js.map +1 -1
  79. package/build/legacy/useMutationState.cjs +94 -0
  80. package/build/legacy/useMutationState.cjs.map +1 -1
  81. package/build/legacy/useMutationState.d.cts +94 -0
  82. package/build/legacy/useMutationState.d.cts.map +1 -1
  83. package/build/legacy/useMutationState.d.ts +94 -0
  84. package/build/legacy/useMutationState.d.ts.map +1 -1
  85. package/build/legacy/useMutationState.js +94 -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 +130 -0
  104. package/build/legacy/useQueries.cjs.map +1 -1
  105. package/build/legacy/useQueries.d.cts +165 -2
  106. package/build/legacy/useQueries.d.cts.map +1 -1
  107. package/build/legacy/useQueries.d.ts +165 -2
  108. package/build/legacy/useQueries.d.ts.map +1 -1
  109. package/build/legacy/useQueries.js +130 -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 +246 -0
  113. package/build/legacy/useQuery.d.cts.map +1 -1
  114. package/build/legacy/useQuery.d.ts +246 -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 +86 -0
  118. package/build/legacy/useSuspenseInfiniteQuery.cjs.map +1 -1
  119. package/build/legacy/useSuspenseInfiniteQuery.d.cts +86 -0
  120. package/build/legacy/useSuspenseInfiniteQuery.d.cts.map +1 -1
  121. package/build/legacy/useSuspenseInfiniteQuery.d.ts +86 -0
  122. package/build/legacy/useSuspenseInfiniteQuery.d.ts.map +1 -1
  123. package/build/legacy/useSuspenseInfiniteQuery.js +86 -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 +320 -2
  127. package/build/legacy/useSuspenseQueries.d.cts.map +1 -1
  128. package/build/legacy/useSuspenseQueries.d.ts +320 -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 +67 -0
  132. package/build/legacy/useSuspenseQuery.cjs.map +1 -1
  133. package/build/legacy/useSuspenseQuery.d.cts +67 -0
  134. package/build/legacy/useSuspenseQuery.d.cts.map +1 -1
  135. package/build/legacy/useSuspenseQuery.d.ts +67 -0
  136. package/build/legacy/useSuspenseQuery.d.ts.map +1 -1
  137. package/build/legacy/useSuspenseQuery.js +67 -0
  138. package/build/legacy/useSuspenseQuery.js.map +1 -1
  139. package/build/modern/HydrationBoundary.cjs +44 -1
  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 +44 -1
  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 +76 -0
  164. package/build/modern/QueryErrorResetBoundary.cjs.map +1 -1
  165. package/build/modern/QueryErrorResetBoundary.d.cts +77 -0
  166. package/build/modern/QueryErrorResetBoundary.d.cts.map +1 -1
  167. package/build/modern/QueryErrorResetBoundary.d.ts +77 -0
  168. package/build/modern/QueryErrorResetBoundary.d.ts.map +1 -1
  169. package/build/modern/QueryErrorResetBoundary.js +76 -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 +173 -0
  173. package/build/modern/infiniteQueryOptions.d.cts.map +1 -1
  174. package/build/modern/infiniteQueryOptions.d.ts +173 -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 +55 -0
  179. package/build/modern/mutationOptions.d.cts.map +1 -1
  180. package/build/modern/mutationOptions.d.ts +55 -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 +175 -0
  185. package/build/modern/queryOptions.d.cts.map +1 -1
  186. package/build/modern/queryOptions.d.ts +175 -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 +292 -0
  197. package/build/modern/useInfiniteQuery.d.cts.map +1 -1
  198. package/build/modern/useInfiniteQuery.d.ts +292 -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 +36 -0
  202. package/build/modern/useIsFetching.cjs.map +1 -1
  203. package/build/modern/useIsFetching.d.cts +36 -0
  204. package/build/modern/useIsFetching.d.cts.map +1 -1
  205. package/build/modern/useIsFetching.d.ts +36 -0
  206. package/build/modern/useIsFetching.d.ts.map +1 -1
  207. package/build/modern/useIsFetching.js +36 -0
  208. package/build/modern/useIsFetching.js.map +1 -1
  209. package/build/modern/useMutation.cjs +172 -0
  210. package/build/modern/useMutation.cjs.map +1 -1
  211. package/build/modern/useMutation.d.cts +172 -0
  212. package/build/modern/useMutation.d.cts.map +1 -1
  213. package/build/modern/useMutation.d.ts +172 -0
  214. package/build/modern/useMutation.d.ts.map +1 -1
  215. package/build/modern/useMutation.js +172 -0
  216. package/build/modern/useMutation.js.map +1 -1
  217. package/build/modern/useMutationState.cjs +94 -0
  218. package/build/modern/useMutationState.cjs.map +1 -1
  219. package/build/modern/useMutationState.d.cts +94 -0
  220. package/build/modern/useMutationState.d.cts.map +1 -1
  221. package/build/modern/useMutationState.d.ts +94 -0
  222. package/build/modern/useMutationState.d.ts.map +1 -1
  223. package/build/modern/useMutationState.js +94 -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 +130 -0
  242. package/build/modern/useQueries.cjs.map +1 -1
  243. package/build/modern/useQueries.d.cts +165 -2
  244. package/build/modern/useQueries.d.cts.map +1 -1
  245. package/build/modern/useQueries.d.ts +165 -2
  246. package/build/modern/useQueries.d.ts.map +1 -1
  247. package/build/modern/useQueries.js +130 -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 +246 -0
  251. package/build/modern/useQuery.d.cts.map +1 -1
  252. package/build/modern/useQuery.d.ts +246 -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 +86 -0
  256. package/build/modern/useSuspenseInfiniteQuery.cjs.map +1 -1
  257. package/build/modern/useSuspenseInfiniteQuery.d.cts +86 -0
  258. package/build/modern/useSuspenseInfiniteQuery.d.cts.map +1 -1
  259. package/build/modern/useSuspenseInfiniteQuery.d.ts +86 -0
  260. package/build/modern/useSuspenseInfiniteQuery.d.ts.map +1 -1
  261. package/build/modern/useSuspenseInfiniteQuery.js +86 -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 +320 -2
  265. package/build/modern/useSuspenseQueries.d.cts.map +1 -1
  266. package/build/modern/useSuspenseQueries.d.ts +320 -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 +67 -0
  270. package/build/modern/useSuspenseQuery.cjs.map +1 -1
  271. package/build/modern/useSuspenseQuery.d.cts +67 -0
  272. package/build/modern/useSuspenseQuery.d.cts.map +1 -1
  273. package/build/modern/useSuspenseQuery.d.ts +67 -0
  274. package/build/modern/useSuspenseQuery.d.ts.map +1 -1
  275. package/build/modern/useSuspenseQuery.js +67 -0
  276. package/build/modern/useSuspenseQuery.js.map +1 -1
  277. package/build/query-codemods/eslint.config.js +7 -0
  278. package/build/query-codemods/root.eslint.config.js +45 -0
  279. package/package.json +11 -11
  280. package/src/HydrationBoundary.tsx +61 -1
  281. package/src/IsRestoringProvider.ts +12 -0
  282. package/src/QueryClientProvider.tsx +41 -0
  283. package/src/QueryErrorResetBoundary.tsx +89 -0
  284. package/src/infiniteQueryOptions.ts +173 -0
  285. package/src/mutationOptions.ts +55 -0
  286. package/src/queryOptions.ts +175 -0
  287. package/src/types.ts +228 -2
  288. package/src/useInfiniteQuery.ts +292 -0
  289. package/src/useIsFetching.ts +36 -0
  290. package/src/useMutation.ts +172 -0
  291. package/src/useMutationState.ts +94 -0
  292. package/src/usePrefetchInfiniteQuery.tsx +44 -0
  293. package/src/usePrefetchQuery.tsx +35 -0
  294. package/src/useQueries.ts +165 -2
  295. package/src/useQuery.ts +246 -0
  296. package/src/useSuspenseInfiniteQuery.ts +86 -0
  297. package/src/useSuspenseQueries.ts +320 -2
  298. package/src/useSuspenseQuery.ts +67 -0
@@ -2,8 +2,254 @@ import { DefinedUseQueryResult, UseQueryOptions, UseQueryResult } from "./types.
2
2
  import { DefinedInitialDataOptions, UndefinedInitialDataOptions } from "./queryOptions.js";
3
3
  import { DefaultError, QueryClient, QueryKey } from "@tanstack/query-core";
4
4
  //#region src/useQuery.d.ts
5
+ /**
6
+ * This overload is selected when `initialData` is set, so the resulting `data` is never `undefined`.
7
+ *
8
+ * @see {@link queryOptions} to share these options between `useQuery` and imperative APIs like `queryClient.query`.
9
+ * @param options - The {@link DefinedInitialDataOptions} to use — everything you can pass to `useQuery`, with `initialData` set.
10
+ * @param queryClient - Use this to use a custom `QueryClient`. Otherwise, the one from the nearest context will
11
+ * be used.
12
+ * @returns The current query result, typed so that `status` is `success` — or `error` if a fetch attempt
13
+ * fails while keeping the existing data (`status` never resolves to `pending` in this overload's type,
14
+ * since `initialData` guarantees data upfront). `isSuccess`/`isError` are derived booleans for convenience.
15
+ *
16
+ * @example
17
+ * ```tsx
18
+ * import { useQuery } from '@tanstack/react-query'
19
+ *
20
+ * function Posts() {
21
+ * // `data` is `Post[]`, never `undefined`, thanks to `initialData` — even if a refetch fails,
22
+ * // so the list stays visible alongside the error.
23
+ * const { data, isError, error } = useQuery({
24
+ * queryKey: ['posts'],
25
+ * queryFn: fetchPosts,
26
+ * initialData: [],
27
+ * })
28
+ *
29
+ * return (
30
+ * <div>
31
+ * {isError ? <span>Error: {error.message}</span> : null}
32
+ * <ul>
33
+ * {data.map((post) => <li key={post.id}>{post.title}</li>)}
34
+ * </ul>
35
+ * </div>
36
+ * )
37
+ * }
38
+ * ```
39
+ */
5
40
  declare function useQuery<TQueryFnData = unknown, TError = DefaultError, TData = TQueryFnData, TQueryKey extends QueryKey = QueryKey>(options: DefinedInitialDataOptions<TQueryFnData, TError, TData, TQueryKey>, queryClient?: QueryClient): DefinedUseQueryResult<TData, TError>;
41
+ /**
42
+ * @see {@link queryOptions} to share these options between `useQuery` and imperative APIs like `queryClient.query`.
43
+ * @param options - The {@link UndefinedInitialDataOptions} to use — everything you can pass to `useQuery`.
44
+ * @param queryClient - Use this to use a custom `QueryClient`. Otherwise, the one from the nearest context will
45
+ * be used.
46
+ * @returns The current query result. `status` is `pending` if there is no cached data to display, `error` if
47
+ * the last fetch attempt failed, or `success` if the query has data to display. `isPending`/`isSuccess`/`isError`
48
+ * are derived booleans for convenience.
49
+ *
50
+ * @example
51
+ * ```tsx
52
+ * import { useQuery } from '@tanstack/react-query'
53
+ *
54
+ * function Posts() {
55
+ * const { status, data, error, isFetching } = useQuery({
56
+ * queryKey: ['posts'],
57
+ * queryFn: fetchPosts,
58
+ * })
59
+ *
60
+ * if (status === 'pending') return 'Loading...'
61
+ * if (status === 'error') return <span>Error: {error.message}</span>
62
+ *
63
+ * return (
64
+ * <div>
65
+ * <ul>
66
+ * {data.map((post) => (
67
+ * <li key={post.id}>{post.title}</li>
68
+ * ))}
69
+ * </ul>
70
+ * <div>{isFetching ? 'Background Updating...' : ' '}</div>
71
+ * </div>
72
+ * )
73
+ * }
74
+ * ```
75
+ *
76
+ * @example
77
+ * The same query, checking `isPending`/`isError` instead of `status` — pick whichever reads better to you:
78
+ * ```tsx
79
+ * import { useQuery } from '@tanstack/react-query'
80
+ *
81
+ * function Posts() {
82
+ * const { isPending, isError, data, error } = useQuery({
83
+ * queryKey: ['posts'],
84
+ * queryFn: fetchPosts,
85
+ * })
86
+ *
87
+ * if (isPending) return 'Loading...'
88
+ * if (isError) return <span>Error: {error.message}</span>
89
+ *
90
+ * return (
91
+ * <ul>
92
+ * {data.map((post) => <li key={post.id}>{post.title}</li>)}
93
+ * </ul>
94
+ * )
95
+ * }
96
+ * ```
97
+ */
6
98
  declare function useQuery<TQueryFnData = unknown, TError = DefaultError, TData = TQueryFnData, TQueryKey extends QueryKey = QueryKey>(options: UndefinedInitialDataOptions<TQueryFnData, TError, TData, TQueryKey>, queryClient?: QueryClient): UseQueryResult<TData, TError>;
99
+ /**
100
+ * @see {@link queryOptions} to share these options between `useQuery` and imperative APIs like `queryClient.query`.
101
+ * @param options - The {@link UseQueryOptions} to use — everything you can pass to `useQuery`.
102
+ * @param queryClient - Use this to use a custom `QueryClient`. Otherwise, the one from the nearest context will
103
+ * be used.
104
+ * @returns The current query result. `status` is `pending` if there is no cached data to display, `error` if
105
+ * the last fetch attempt failed, or `success` if the query has data to display. `isPending`/`isSuccess`/`isError`
106
+ * are derived booleans for convenience.
107
+ *
108
+ * @example
109
+ * ```tsx
110
+ * import { useQuery } from '@tanstack/react-query'
111
+ *
112
+ * function Posts() {
113
+ * const { status, data, error, isFetching } = useQuery({
114
+ * queryKey: ['posts'],
115
+ * queryFn: fetchPosts,
116
+ * })
117
+ *
118
+ * if (status === 'pending') return 'Loading...'
119
+ * if (status === 'error') return <span>Error: {error.message}</span>
120
+ *
121
+ * return (
122
+ * <div>
123
+ * <ul>
124
+ * {data.map((post) => (
125
+ * <li key={post.id}>{post.title}</li>
126
+ * ))}
127
+ * </ul>
128
+ * <div>{isFetching ? 'Background Updating...' : ' '}</div>
129
+ * </div>
130
+ * )
131
+ * }
132
+ * ```
133
+ *
134
+ * @example
135
+ * `select` derives whatever `data` a component needs from the cached value, without changing what's
136
+ * actually stored in the cache — the cache still holds the full `Post[]`, but `data` here is a `number`:
137
+ * ```tsx
138
+ * import { useQuery } from '@tanstack/react-query'
139
+ *
140
+ * function PostCount() {
141
+ * const { data, isPending, isError, error } = useQuery({
142
+ * queryKey: ['posts'],
143
+ * queryFn: fetchPosts,
144
+ * select: (posts) => posts.length,
145
+ * })
146
+ *
147
+ * if (isPending) return 'Loading...'
148
+ * if (isError) return <span>Error: {error.message}</span>
149
+ *
150
+ * return <span>{data} posts</span>
151
+ * }
152
+ * ```
153
+ *
154
+ * @example
155
+ * A dependent query, only enabled once `postId` is set — use `isLoading`, not `isPending`, so the
156
+ * loading state doesn't show while the query is disabled:
157
+ * ```tsx
158
+ * import { useQuery } from '@tanstack/react-query'
159
+ *
160
+ * function Post({ postId }: { postId: number | undefined }) {
161
+ * const { data, isLoading, isError, error } = useQuery({
162
+ * queryKey: ['post', postId],
163
+ * queryFn: () => fetchPost(postId!),
164
+ * enabled: postId != null,
165
+ * })
166
+ *
167
+ * if (postId == null) return 'Select a post'
168
+ * if (isLoading) return 'Loading...'
169
+ * if (isError) return <span>Error: {error.message}</span>
170
+ *
171
+ * return <h1>{data?.title}</h1>
172
+ * }
173
+ * ```
174
+ *
175
+ * @example
176
+ * The same dependent query, type safe: `skipToken` disables the query without needing the
177
+ * non-null assertion above, since `queryFn` is only ever called when `postId` is defined.
178
+ * `refetch` doesn't work while `queryFn` is `skipToken` — use `enabled: false` instead if you
179
+ * need to trigger the query manually:
180
+ * ```tsx
181
+ * import { skipToken, useQuery } from '@tanstack/react-query'
182
+ *
183
+ * function Post({ postId }: { postId: number | undefined }) {
184
+ * const { data, isLoading, isError, error } = useQuery({
185
+ * queryKey: ['post', postId],
186
+ * queryFn: postId != null ? () => fetchPost(postId) : skipToken,
187
+ * })
188
+ *
189
+ * if (postId == null) return 'Select a post'
190
+ * if (isLoading) return 'Loading...'
191
+ * if (isError) return <span>Error: {error.message}</span>
192
+ *
193
+ * return <h1>{data?.title}</h1>
194
+ * }
195
+ * ```
196
+ *
197
+ * @example
198
+ * Seeding a detail query from an already-cached list, to skip the loading state:
199
+ * ```tsx
200
+ * import { useQuery, useQueryClient } from '@tanstack/react-query'
201
+ *
202
+ * function Post({ postId }: { postId: number }) {
203
+ * const queryClient = useQueryClient()
204
+ *
205
+ * const { data, isError, error } = useQuery({
206
+ * queryKey: ['post', postId],
207
+ * queryFn: () => fetchPost(postId),
208
+ * initialData: () =>
209
+ * queryClient
210
+ * .getQueryData<Array<Post>>(['posts'])
211
+ * ?.find((post) => post.id === postId),
212
+ * })
213
+ *
214
+ * if (isError) return <span>Error: {error.message}</span>
215
+ *
216
+ * return <h1>{data?.title}</h1>
217
+ * }
218
+ * ```
219
+ *
220
+ * @example
221
+ * Paginated data, keeping the previous page's data visible while the next page loads:
222
+ * ```tsx
223
+ * import { keepPreviousData, useQuery } from '@tanstack/react-query'
224
+ * import { useState } from 'react'
225
+ *
226
+ * function Posts() {
227
+ * const [page, setPage] = useState(0)
228
+ *
229
+ * const { data, isPlaceholderData, isError, error } = useQuery({
230
+ * queryKey: ['posts', page],
231
+ * queryFn: () => fetchPosts(page),
232
+ * placeholderData: keepPreviousData,
233
+ * })
234
+ *
235
+ * if (isError) return <span>Error: {error.message}</span>
236
+ *
237
+ * return (
238
+ * <div>
239
+ * <ul>
240
+ * {data?.map((post) => <li key={post.id}>{post.title}</li>)}
241
+ * </ul>
242
+ * <button
243
+ * disabled={isPlaceholderData}
244
+ * onClick={() => setPage((old) => old + 1)}
245
+ * >
246
+ * Next Page
247
+ * </button>
248
+ * </div>
249
+ * )
250
+ * }
251
+ * ```
252
+ */
7
253
  declare function useQuery<TQueryFnData = unknown, TError = DefaultError, TData = TQueryFnData, TQueryKey extends QueryKey = QueryKey>(options: UseQueryOptions<TQueryFnData, TError, TData, TQueryKey>, queryClient?: QueryClient): UseQueryResult<TData, TError>;
8
254
  //#endregion
9
255
  export { useQuery };
@@ -1 +1 @@
1
- {"version":3,"file":"useQuery.d.ts","names":[],"sources":["../../src/useQuery.ts"],"mappings":";;;;iBAcgB,SACd,wBACA,SAAS,cACT,QAAQ,cACR,kBAAkB,WAAW,UAE7B,SAAS,0BAA0B,cAAc,QAAQ,OAAO,YAChE,cAAc,cACb,sBAAsB,OAAO;iBAEhB,SACd,wBACA,SAAS,cACT,QAAQ,cACR,kBAAkB,WAAW,UAE7B,SAAS,4BAA4B,cAAc,QAAQ,OAAO,YAClE,cAAc,cACb,eAAe,OAAO;iBAET,SACd,wBACA,SAAS,cACT,QAAQ,cACR,kBAAkB,WAAW,UAE7B,SAAS,gBAAgB,cAAc,QAAQ,OAAO,YACtD,cAAc,cACb,eAAe,OAAO"}
1
+ {"version":3,"file":"useQuery.d.ts","names":[],"sources":["../../src/useQuery.ts"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;iBAiDgB,SACd,wBACA,SAAS,cACT,QAAQ,cACR,kBAAkB,WAAW,UAE7B,SAAS,0BAA0B,cAAc,QAAQ,OAAO,YAChE,cAAc,cACb,sBAAsB,OAAO;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;iBA2DhB,SACd,wBACA,SAAS,cACT,QAAQ,cACR,kBAAkB,WAAW,UAE7B,SAAS,4BAA4B,cAAc,QAAQ,OAAO,YAClE,cAAc,cACb,eAAe,OAAO;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;iBA4JT,SACd,wBACA,SAAS,cACT,QAAQ,cACR,kBAAkB,WAAW,UAE7B,SAAS,gBAAgB,cAAc,QAAQ,OAAO,YACtD,cAAc,cACb,eAAe,OAAO"}
@@ -1 +1 @@
1
- {"version":3,"file":"useQuery.js","names":[],"sources":["../../src/useQuery.ts"],"sourcesContent":["'use client'\nimport { QueryObserver } from '@tanstack/query-core'\nimport { useBaseQuery } from './useBaseQuery'\nimport type { DefaultError, QueryClient, QueryKey } from '@tanstack/query-core'\nimport type {\n DefinedUseQueryResult,\n UseQueryOptions,\n UseQueryResult,\n} from './types'\nimport type {\n DefinedInitialDataOptions,\n UndefinedInitialDataOptions,\n} from './queryOptions'\n\nexport function useQuery<\n TQueryFnData = unknown,\n TError = DefaultError,\n TData = TQueryFnData,\n TQueryKey extends QueryKey = QueryKey,\n>(\n options: DefinedInitialDataOptions<TQueryFnData, TError, TData, TQueryKey>,\n queryClient?: QueryClient,\n): DefinedUseQueryResult<TData, TError>\n\nexport function useQuery<\n TQueryFnData = unknown,\n TError = DefaultError,\n TData = TQueryFnData,\n TQueryKey extends QueryKey = QueryKey,\n>(\n options: UndefinedInitialDataOptions<TQueryFnData, TError, TData, TQueryKey>,\n queryClient?: QueryClient,\n): UseQueryResult<TData, TError>\n\nexport function useQuery<\n TQueryFnData = unknown,\n TError = DefaultError,\n TData = TQueryFnData,\n TQueryKey extends QueryKey = QueryKey,\n>(\n options: UseQueryOptions<TQueryFnData, TError, TData, TQueryKey>,\n queryClient?: QueryClient,\n): UseQueryResult<TData, TError>\n\nexport function useQuery(options: UseQueryOptions, queryClient?: QueryClient) {\n return useBaseQuery(options, QueryObserver, queryClient)\n}\n"],"mappings":";;;;AA4CA,SAAgB,SAAS,SAA0B,aAA2B;CAC5E,OAAO,aAAa,SAAS,eAAe,WAAW;AACzD"}
1
+ {"version":3,"file":"useQuery.js","names":[],"sources":["../../src/useQuery.ts"],"sourcesContent":["'use client'\nimport { QueryObserver } from '@tanstack/query-core'\nimport { useBaseQuery } from './useBaseQuery'\nimport type { DefaultError, QueryClient, QueryKey } from '@tanstack/query-core'\nimport type {\n DefinedUseQueryResult,\n UseQueryOptions,\n UseQueryResult,\n} from './types'\nimport type {\n DefinedInitialDataOptions,\n UndefinedInitialDataOptions,\n} from './queryOptions'\n\n/**\n * This overload is selected when `initialData` is set, so the resulting `data` is never `undefined`.\n *\n * @see {@link queryOptions} to share these options between `useQuery` and imperative APIs like `queryClient.query`.\n * @param options - The {@link DefinedInitialDataOptions} to use — everything you can pass to `useQuery`, with `initialData` set.\n * @param queryClient - Use this to use a custom `QueryClient`. Otherwise, the one from the nearest context will\n * be used.\n * @returns The current query result, typed so that `status` is `success` — or `error` if a fetch attempt\n * fails while keeping the existing data (`status` never resolves to `pending` in this overload's type,\n * since `initialData` guarantees data upfront). `isSuccess`/`isError` are derived booleans for convenience.\n *\n * @example\n * ```tsx\n * import { useQuery } from '@tanstack/react-query'\n *\n * function Posts() {\n * // `data` is `Post[]`, never `undefined`, thanks to `initialData` — even if a refetch fails,\n * // so the list stays visible alongside the error.\n * const { data, isError, error } = useQuery({\n * queryKey: ['posts'],\n * queryFn: fetchPosts,\n * initialData: [],\n * })\n *\n * return (\n * <div>\n * {isError ? <span>Error: {error.message}</span> : null}\n * <ul>\n * {data.map((post) => <li key={post.id}>{post.title}</li>)}\n * </ul>\n * </div>\n * )\n * }\n * ```\n */\nexport function useQuery<\n TQueryFnData = unknown,\n TError = DefaultError,\n TData = TQueryFnData,\n TQueryKey extends QueryKey = QueryKey,\n>(\n options: DefinedInitialDataOptions<TQueryFnData, TError, TData, TQueryKey>,\n queryClient?: QueryClient,\n): DefinedUseQueryResult<TData, TError>\n\n/**\n * @see {@link queryOptions} to share these options between `useQuery` and imperative APIs like `queryClient.query`.\n * @param options - The {@link UndefinedInitialDataOptions} to use — everything you can pass to `useQuery`.\n * @param queryClient - Use this to use a custom `QueryClient`. Otherwise, the one from the nearest context will\n * be used.\n * @returns The current query result. `status` is `pending` if there is no cached data to display, `error` if\n * the last fetch attempt failed, or `success` if the query has data to display. `isPending`/`isSuccess`/`isError`\n * are derived booleans for convenience.\n *\n * @example\n * ```tsx\n * import { useQuery } from '@tanstack/react-query'\n *\n * function Posts() {\n * const { status, data, error, isFetching } = useQuery({\n * queryKey: ['posts'],\n * queryFn: fetchPosts,\n * })\n *\n * if (status === 'pending') return 'Loading...'\n * if (status === 'error') return <span>Error: {error.message}</span>\n *\n * return (\n * <div>\n * <ul>\n * {data.map((post) => (\n * <li key={post.id}>{post.title}</li>\n * ))}\n * </ul>\n * <div>{isFetching ? 'Background Updating...' : ' '}</div>\n * </div>\n * )\n * }\n * ```\n *\n * @example\n * The same query, checking `isPending`/`isError` instead of `status` — pick whichever reads better to you:\n * ```tsx\n * import { useQuery } from '@tanstack/react-query'\n *\n * function Posts() {\n * const { isPending, isError, data, error } = useQuery({\n * queryKey: ['posts'],\n * queryFn: fetchPosts,\n * })\n *\n * if (isPending) return 'Loading...'\n * if (isError) return <span>Error: {error.message}</span>\n *\n * return (\n * <ul>\n * {data.map((post) => <li key={post.id}>{post.title}</li>)}\n * </ul>\n * )\n * }\n * ```\n */\nexport function useQuery<\n TQueryFnData = unknown,\n TError = DefaultError,\n TData = TQueryFnData,\n TQueryKey extends QueryKey = QueryKey,\n>(\n options: UndefinedInitialDataOptions<TQueryFnData, TError, TData, TQueryKey>,\n queryClient?: QueryClient,\n): UseQueryResult<TData, TError>\n\n/**\n * @see {@link queryOptions} to share these options between `useQuery` and imperative APIs like `queryClient.query`.\n * @param options - The {@link UseQueryOptions} to use — everything you can pass to `useQuery`.\n * @param queryClient - Use this to use a custom `QueryClient`. Otherwise, the one from the nearest context will\n * be used.\n * @returns The current query result. `status` is `pending` if there is no cached data to display, `error` if\n * the last fetch attempt failed, or `success` if the query has data to display. `isPending`/`isSuccess`/`isError`\n * are derived booleans for convenience.\n *\n * @example\n * ```tsx\n * import { useQuery } from '@tanstack/react-query'\n *\n * function Posts() {\n * const { status, data, error, isFetching } = useQuery({\n * queryKey: ['posts'],\n * queryFn: fetchPosts,\n * })\n *\n * if (status === 'pending') return 'Loading...'\n * if (status === 'error') return <span>Error: {error.message}</span>\n *\n * return (\n * <div>\n * <ul>\n * {data.map((post) => (\n * <li key={post.id}>{post.title}</li>\n * ))}\n * </ul>\n * <div>{isFetching ? 'Background Updating...' : ' '}</div>\n * </div>\n * )\n * }\n * ```\n *\n * @example\n * `select` derives whatever `data` a component needs from the cached value, without changing what's\n * actually stored in the cache — the cache still holds the full `Post[]`, but `data` here is a `number`:\n * ```tsx\n * import { useQuery } from '@tanstack/react-query'\n *\n * function PostCount() {\n * const { data, isPending, isError, error } = useQuery({\n * queryKey: ['posts'],\n * queryFn: fetchPosts,\n * select: (posts) => posts.length,\n * })\n *\n * if (isPending) return 'Loading...'\n * if (isError) return <span>Error: {error.message}</span>\n *\n * return <span>{data} posts</span>\n * }\n * ```\n *\n * @example\n * A dependent query, only enabled once `postId` is set — use `isLoading`, not `isPending`, so the\n * loading state doesn't show while the query is disabled:\n * ```tsx\n * import { useQuery } from '@tanstack/react-query'\n *\n * function Post({ postId }: { postId: number | undefined }) {\n * const { data, isLoading, isError, error } = useQuery({\n * queryKey: ['post', postId],\n * queryFn: () => fetchPost(postId!),\n * enabled: postId != null,\n * })\n *\n * if (postId == null) return 'Select a post'\n * if (isLoading) return 'Loading...'\n * if (isError) return <span>Error: {error.message}</span>\n *\n * return <h1>{data?.title}</h1>\n * }\n * ```\n *\n * @example\n * The same dependent query, type safe: `skipToken` disables the query without needing the\n * non-null assertion above, since `queryFn` is only ever called when `postId` is defined.\n * `refetch` doesn't work while `queryFn` is `skipToken` — use `enabled: false` instead if you\n * need to trigger the query manually:\n * ```tsx\n * import { skipToken, useQuery } from '@tanstack/react-query'\n *\n * function Post({ postId }: { postId: number | undefined }) {\n * const { data, isLoading, isError, error } = useQuery({\n * queryKey: ['post', postId],\n * queryFn: postId != null ? () => fetchPost(postId) : skipToken,\n * })\n *\n * if (postId == null) return 'Select a post'\n * if (isLoading) return 'Loading...'\n * if (isError) return <span>Error: {error.message}</span>\n *\n * return <h1>{data?.title}</h1>\n * }\n * ```\n *\n * @example\n * Seeding a detail query from an already-cached list, to skip the loading state:\n * ```tsx\n * import { useQuery, useQueryClient } from '@tanstack/react-query'\n *\n * function Post({ postId }: { postId: number }) {\n * const queryClient = useQueryClient()\n *\n * const { data, isError, error } = useQuery({\n * queryKey: ['post', postId],\n * queryFn: () => fetchPost(postId),\n * initialData: () =>\n * queryClient\n * .getQueryData<Array<Post>>(['posts'])\n * ?.find((post) => post.id === postId),\n * })\n *\n * if (isError) return <span>Error: {error.message}</span>\n *\n * return <h1>{data?.title}</h1>\n * }\n * ```\n *\n * @example\n * Paginated data, keeping the previous page's data visible while the next page loads:\n * ```tsx\n * import { keepPreviousData, useQuery } from '@tanstack/react-query'\n * import { useState } from 'react'\n *\n * function Posts() {\n * const [page, setPage] = useState(0)\n *\n * const { data, isPlaceholderData, isError, error } = useQuery({\n * queryKey: ['posts', page],\n * queryFn: () => fetchPosts(page),\n * placeholderData: keepPreviousData,\n * })\n *\n * if (isError) return <span>Error: {error.message}</span>\n *\n * return (\n * <div>\n * <ul>\n * {data?.map((post) => <li key={post.id}>{post.title}</li>)}\n * </ul>\n * <button\n * disabled={isPlaceholderData}\n * onClick={() => setPage((old) => old + 1)}\n * >\n * Next Page\n * </button>\n * </div>\n * )\n * }\n * ```\n */\nexport function useQuery<\n TQueryFnData = unknown,\n TError = DefaultError,\n TData = TQueryFnData,\n TQueryKey extends QueryKey = QueryKey,\n>(\n options: UseQueryOptions<TQueryFnData, TError, TData, TQueryKey>,\n queryClient?: QueryClient,\n): UseQueryResult<TData, TError>\n\nexport function useQuery(options: UseQueryOptions, queryClient?: QueryClient) {\n return useBaseQuery(options, QueryObserver, queryClient)\n}\n"],"mappings":";;;;AAkSA,SAAgB,SAAS,SAA0B,aAA2B;CAC5E,OAAO,aAAa,SAAS,eAAe,WAAW;AACzD"}
@@ -4,6 +4,92 @@ const require_suspense = require("./suspense.cjs");
4
4
  const require_useBaseQuery = require("./useBaseQuery.cjs");
5
5
  let _tanstack_query_core = require("@tanstack/query-core");
6
6
  //#region src/useSuspenseInfiniteQuery.ts
7
+ /**
8
+ * The options for `useSuspenseInfiniteQuery` are the same as for `useInfiniteQuery`, except for `throwOnError`,
9
+ * `enabled`, and `placeholderData`.
10
+ *
11
+ * Caveat: cancellation does not work.
12
+ *
13
+ * @remarks Multiple suspenseful query calls in the same component suspend serially, causing a request
14
+ * waterfall — each one blocks rendering until it resolves, so the next doesn't even start fetching until
15
+ * then. There's no way to parallelize multiple infinite queries under Suspense. Also keep in mind that
16
+ * imperative fetch calls, such as `fetchNextPage`, may interfere with the default refetch behavior,
17
+ * resulting in outdated data. Make sure to call these functions only in response to user actions, or add
18
+ * conditions like `hasNextPage && !isFetching`.
19
+ * @see {@link useInfiniteQuery} for the non-Suspense version of this hook.
20
+ * @param options - The {@link UseSuspenseInfiniteQueryOptions} to use — the same options as `useInfiniteQuery`, minus the ones listed above.
21
+ * @param queryClient - Use this to use a custom `QueryClient`. Otherwise, the one from the nearest context will
22
+ * be used.
23
+ * @returns The same object as `useInfiniteQuery`, except that `data` is guaranteed to be defined,
24
+ * `isPlaceholderData` is missing, and `status` is either `success` or `error` (with the derived flags set
25
+ * accordingly).
26
+ *
27
+ * @example
28
+ * The query error is thrown if a fetch fails and no cached data exists yet, so an error boundary is
29
+ * required around `<Suspense>`. A failed background refetch instead continues to render the cached data.
30
+ * Use {@link QueryErrorResetBoundary} to let the user retry after such an error:
31
+ * ```tsx
32
+ * import { Suspense } from 'react'
33
+ * import { ErrorBoundary } from 'react-error-boundary'
34
+ * import {
35
+ * QueryErrorResetBoundary,
36
+ * useSuspenseInfiniteQuery,
37
+ * } from '@tanstack/react-query'
38
+ *
39
+ * function Projects() {
40
+ * // `data` is guaranteed to be defined here — no `isPending` check needed.
41
+ * const { data, fetchNextPage, hasNextPage, isFetching, isFetchingNextPage } =
42
+ * useSuspenseInfiniteQuery({
43
+ * queryKey: ['projects'],
44
+ * queryFn: ({ pageParam }) => fetchProjects(pageParam),
45
+ * initialPageParam: 0,
46
+ * getNextPageParam: (lastPage) => lastPage.nextId,
47
+ * })
48
+ *
49
+ * return (
50
+ * <div>
51
+ * <ul>
52
+ * {data.pages.map((page) =>
53
+ * page.projects.map((project) => <li key={project.id}>{project.name}</li>),
54
+ * )}
55
+ * </ul>
56
+ * <button
57
+ * onClick={() => fetchNextPage()}
58
+ * disabled={!hasNextPage || isFetching}
59
+ * >
60
+ * {isFetchingNextPage
61
+ * ? 'Loading more...'
62
+ * : hasNextPage
63
+ * ? 'Load More'
64
+ * : 'Nothing more to load'}
65
+ * </button>
66
+ * </div>
67
+ * )
68
+ * }
69
+ *
70
+ * function App() {
71
+ * return (
72
+ * <QueryErrorResetBoundary>
73
+ * {({ reset }) => (
74
+ * <ErrorBoundary
75
+ * onReset={reset}
76
+ * fallbackRender={({ resetErrorBoundary }) => (
77
+ * <div>
78
+ * There was an error!
79
+ * <button onClick={() => resetErrorBoundary()}>Try again</button>
80
+ * </div>
81
+ * )}
82
+ * >
83
+ * <Suspense fallback={<h1>Loading projects...</h1>}>
84
+ * <Projects />
85
+ * </Suspense>
86
+ * </ErrorBoundary>
87
+ * )}
88
+ * </QueryErrorResetBoundary>
89
+ * )
90
+ * }
91
+ * ```
92
+ */
7
93
  function useSuspenseInfiniteQuery(options, queryClient) {
8
94
  if (process.env.NODE_ENV !== "production") {
9
95
  if (options.queryFn === _tanstack_query_core.skipToken) console.error("skipToken is not allowed for useSuspenseInfiniteQuery");
@@ -1 +1 @@
1
- {"version":3,"file":"useSuspenseInfiniteQuery.cjs","names":["skipToken","useBaseQuery","defaultThrowOnError","InfiniteQueryObserver"],"sources":["../../src/useSuspenseInfiniteQuery.ts"],"sourcesContent":["'use client'\nimport { InfiniteQueryObserver, skipToken } from '@tanstack/query-core'\nimport { useBaseQuery } from './useBaseQuery'\nimport { defaultThrowOnError } from './suspense'\nimport type {\n DefaultError,\n InfiniteData,\n InfiniteQueryObserverSuccessResult,\n QueryClient,\n QueryKey,\n QueryObserver,\n} from '@tanstack/query-core'\nimport type {\n UseSuspenseInfiniteQueryOptions,\n UseSuspenseInfiniteQueryResult,\n} from './types'\n\nexport function useSuspenseInfiniteQuery<\n TQueryFnData,\n TError = DefaultError,\n TData = InfiniteData<TQueryFnData>,\n TQueryKey extends QueryKey = QueryKey,\n TPageParam = unknown,\n>(\n options: UseSuspenseInfiniteQueryOptions<\n TQueryFnData,\n TError,\n TData,\n TQueryKey,\n TPageParam\n >,\n queryClient?: QueryClient,\n): UseSuspenseInfiniteQueryResult<TData, TError> {\n if (process.env.NODE_ENV !== 'production') {\n if ((options.queryFn as any) === skipToken) {\n console.error('skipToken is not allowed for useSuspenseInfiniteQuery')\n }\n }\n\n return useBaseQuery(\n {\n ...options,\n enabled: true,\n suspense: true,\n throwOnError: defaultThrowOnError,\n placeholderData: undefined,\n },\n InfiniteQueryObserver as typeof QueryObserver,\n queryClient,\n ) as InfiniteQueryObserverSuccessResult<TData, TError>\n}\n"],"mappings":";;;;;;AAiBA,SAAgB,yBAOd,SAOA,aAC+C;CAC/C,IAAI,QAAQ,IAAI,aAAa,cACtB;MAAA,QAAQ,YAAoBA,qBAAAA,WAC/B,QAAQ,MAAM,uDAAuD;CAAA;CAIzE,OAAOC,qBAAAA,aACL;EACE,GAAG;EACH,SAAS;EACT,UAAU;EACV,cAAcC,iBAAAA;EACd,iBAAiB,KAAA;CACnB,GACAC,qBAAAA,uBACA,WACF;AACF"}
1
+ {"version":3,"file":"useSuspenseInfiniteQuery.cjs","names":["skipToken","useBaseQuery","defaultThrowOnError","InfiniteQueryObserver"],"sources":["../../src/useSuspenseInfiniteQuery.ts"],"sourcesContent":["'use client'\nimport { InfiniteQueryObserver, skipToken } from '@tanstack/query-core'\nimport { useBaseQuery } from './useBaseQuery'\nimport { defaultThrowOnError } from './suspense'\nimport type {\n DefaultError,\n InfiniteData,\n InfiniteQueryObserverSuccessResult,\n QueryClient,\n QueryKey,\n QueryObserver,\n} from '@tanstack/query-core'\nimport type {\n UseSuspenseInfiniteQueryOptions,\n UseSuspenseInfiniteQueryResult,\n} from './types'\n\n/**\n * The options for `useSuspenseInfiniteQuery` are the same as for `useInfiniteQuery`, except for `throwOnError`,\n * `enabled`, and `placeholderData`.\n *\n * Caveat: cancellation does not work.\n *\n * @remarks Multiple suspenseful query calls in the same component suspend serially, causing a request\n * waterfall — each one blocks rendering until it resolves, so the next doesn't even start fetching until\n * then. There's no way to parallelize multiple infinite queries under Suspense. Also keep in mind that\n * imperative fetch calls, such as `fetchNextPage`, may interfere with the default refetch behavior,\n * resulting in outdated data. Make sure to call these functions only in response to user actions, or add\n * conditions like `hasNextPage && !isFetching`.\n * @see {@link useInfiniteQuery} for the non-Suspense version of this hook.\n * @param options - The {@link UseSuspenseInfiniteQueryOptions} to use — the same options as `useInfiniteQuery`, minus the ones listed above.\n * @param queryClient - Use this to use a custom `QueryClient`. Otherwise, the one from the nearest context will\n * be used.\n * @returns The same object as `useInfiniteQuery`, except that `data` is guaranteed to be defined,\n * `isPlaceholderData` is missing, and `status` is either `success` or `error` (with the derived flags set\n * accordingly).\n *\n * @example\n * The query error is thrown if a fetch fails and no cached data exists yet, so an error boundary is\n * required around `<Suspense>`. A failed background refetch instead continues to render the cached data.\n * Use {@link QueryErrorResetBoundary} to let the user retry after such an error:\n * ```tsx\n * import { Suspense } from 'react'\n * import { ErrorBoundary } from 'react-error-boundary'\n * import {\n * QueryErrorResetBoundary,\n * useSuspenseInfiniteQuery,\n * } from '@tanstack/react-query'\n *\n * function Projects() {\n * // `data` is guaranteed to be defined here — no `isPending` check needed.\n * const { data, fetchNextPage, hasNextPage, isFetching, isFetchingNextPage } =\n * useSuspenseInfiniteQuery({\n * queryKey: ['projects'],\n * queryFn: ({ pageParam }) => fetchProjects(pageParam),\n * initialPageParam: 0,\n * getNextPageParam: (lastPage) => lastPage.nextId,\n * })\n *\n * return (\n * <div>\n * <ul>\n * {data.pages.map((page) =>\n * page.projects.map((project) => <li key={project.id}>{project.name}</li>),\n * )}\n * </ul>\n * <button\n * onClick={() => fetchNextPage()}\n * disabled={!hasNextPage || isFetching}\n * >\n * {isFetchingNextPage\n * ? 'Loading more...'\n * : hasNextPage\n * ? 'Load More'\n * : 'Nothing more to load'}\n * </button>\n * </div>\n * )\n * }\n *\n * function App() {\n * return (\n * <QueryErrorResetBoundary>\n * {({ reset }) => (\n * <ErrorBoundary\n * onReset={reset}\n * fallbackRender={({ resetErrorBoundary }) => (\n * <div>\n * There was an error!\n * <button onClick={() => resetErrorBoundary()}>Try again</button>\n * </div>\n * )}\n * >\n * <Suspense fallback={<h1>Loading projects...</h1>}>\n * <Projects />\n * </Suspense>\n * </ErrorBoundary>\n * )}\n * </QueryErrorResetBoundary>\n * )\n * }\n * ```\n */\nexport function useSuspenseInfiniteQuery<\n TQueryFnData,\n TError = DefaultError,\n TData = InfiniteData<TQueryFnData>,\n TQueryKey extends QueryKey = QueryKey,\n TPageParam = unknown,\n>(\n options: UseSuspenseInfiniteQueryOptions<\n TQueryFnData,\n TError,\n TData,\n TQueryKey,\n TPageParam\n >,\n queryClient?: QueryClient,\n): UseSuspenseInfiniteQueryResult<TData, TError> {\n if (process.env.NODE_ENV !== 'production') {\n if ((options.queryFn as any) === skipToken) {\n console.error('skipToken is not allowed for useSuspenseInfiniteQuery')\n }\n }\n\n return useBaseQuery(\n {\n ...options,\n enabled: true,\n suspense: true,\n throwOnError: defaultThrowOnError,\n placeholderData: undefined,\n },\n InfiniteQueryObserver as typeof QueryObserver,\n queryClient,\n ) as InfiniteQueryObserverSuccessResult<TData, TError>\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAuGA,SAAgB,yBAOd,SAOA,aAC+C;CAC/C,IAAI,QAAQ,IAAI,aAAa,cACtB;MAAA,QAAQ,YAAoBA,qBAAAA,WAC/B,QAAQ,MAAM,uDAAuD;CAAA;CAIzE,OAAOC,qBAAAA,aACL;EACE,GAAG;EACH,SAAS;EACT,UAAU;EACV,cAAcC,iBAAAA;EACd,iBAAiB,KAAA;CACnB,GACAC,qBAAAA,uBACA,WACF;AACF"}
@@ -1,6 +1,92 @@
1
1
  import { UseSuspenseInfiniteQueryOptions, UseSuspenseInfiniteQueryResult } from "./types.cjs";
2
2
  import { DefaultError, InfiniteData, QueryClient, QueryKey } from "@tanstack/query-core";
3
3
  //#region src/useSuspenseInfiniteQuery.d.ts
4
+ /**
5
+ * The options for `useSuspenseInfiniteQuery` are the same as for `useInfiniteQuery`, except for `throwOnError`,
6
+ * `enabled`, and `placeholderData`.
7
+ *
8
+ * Caveat: cancellation does not work.
9
+ *
10
+ * @remarks Multiple suspenseful query calls in the same component suspend serially, causing a request
11
+ * waterfall — each one blocks rendering until it resolves, so the next doesn't even start fetching until
12
+ * then. There's no way to parallelize multiple infinite queries under Suspense. Also keep in mind that
13
+ * imperative fetch calls, such as `fetchNextPage`, may interfere with the default refetch behavior,
14
+ * resulting in outdated data. Make sure to call these functions only in response to user actions, or add
15
+ * conditions like `hasNextPage && !isFetching`.
16
+ * @see {@link useInfiniteQuery} for the non-Suspense version of this hook.
17
+ * @param options - The {@link UseSuspenseInfiniteQueryOptions} to use — the same options as `useInfiniteQuery`, minus the ones listed above.
18
+ * @param queryClient - Use this to use a custom `QueryClient`. Otherwise, the one from the nearest context will
19
+ * be used.
20
+ * @returns The same object as `useInfiniteQuery`, except that `data` is guaranteed to be defined,
21
+ * `isPlaceholderData` is missing, and `status` is either `success` or `error` (with the derived flags set
22
+ * accordingly).
23
+ *
24
+ * @example
25
+ * The query error is thrown if a fetch fails and no cached data exists yet, so an error boundary is
26
+ * required around `<Suspense>`. A failed background refetch instead continues to render the cached data.
27
+ * Use {@link QueryErrorResetBoundary} to let the user retry after such an error:
28
+ * ```tsx
29
+ * import { Suspense } from 'react'
30
+ * import { ErrorBoundary } from 'react-error-boundary'
31
+ * import {
32
+ * QueryErrorResetBoundary,
33
+ * useSuspenseInfiniteQuery,
34
+ * } from '@tanstack/react-query'
35
+ *
36
+ * function Projects() {
37
+ * // `data` is guaranteed to be defined here — no `isPending` check needed.
38
+ * const { data, fetchNextPage, hasNextPage, isFetching, isFetchingNextPage } =
39
+ * useSuspenseInfiniteQuery({
40
+ * queryKey: ['projects'],
41
+ * queryFn: ({ pageParam }) => fetchProjects(pageParam),
42
+ * initialPageParam: 0,
43
+ * getNextPageParam: (lastPage) => lastPage.nextId,
44
+ * })
45
+ *
46
+ * return (
47
+ * <div>
48
+ * <ul>
49
+ * {data.pages.map((page) =>
50
+ * page.projects.map((project) => <li key={project.id}>{project.name}</li>),
51
+ * )}
52
+ * </ul>
53
+ * <button
54
+ * onClick={() => fetchNextPage()}
55
+ * disabled={!hasNextPage || isFetching}
56
+ * >
57
+ * {isFetchingNextPage
58
+ * ? 'Loading more...'
59
+ * : hasNextPage
60
+ * ? 'Load More'
61
+ * : 'Nothing more to load'}
62
+ * </button>
63
+ * </div>
64
+ * )
65
+ * }
66
+ *
67
+ * function App() {
68
+ * return (
69
+ * <QueryErrorResetBoundary>
70
+ * {({ reset }) => (
71
+ * <ErrorBoundary
72
+ * onReset={reset}
73
+ * fallbackRender={({ resetErrorBoundary }) => (
74
+ * <div>
75
+ * There was an error!
76
+ * <button onClick={() => resetErrorBoundary()}>Try again</button>
77
+ * </div>
78
+ * )}
79
+ * >
80
+ * <Suspense fallback={<h1>Loading projects...</h1>}>
81
+ * <Projects />
82
+ * </Suspense>
83
+ * </ErrorBoundary>
84
+ * )}
85
+ * </QueryErrorResetBoundary>
86
+ * )
87
+ * }
88
+ * ```
89
+ */
4
90
  declare function useSuspenseInfiniteQuery<TQueryFnData, TError = DefaultError, TData = InfiniteData<TQueryFnData>, TQueryKey extends QueryKey = QueryKey, TPageParam = unknown>(options: UseSuspenseInfiniteQueryOptions<TQueryFnData, TError, TData, TQueryKey, TPageParam>, queryClient?: QueryClient): UseSuspenseInfiniteQueryResult<TData, TError>;
5
91
  //#endregion
6
92
  export { useSuspenseInfiniteQuery };
@@ -1 +1 @@
1
- {"version":3,"file":"useSuspenseInfiniteQuery.d.cts","names":[],"sources":["../../src/useSuspenseInfiniteQuery.ts"],"mappings":";;;iBAiBgB,yBACd,cACA,SAAS,cACT,QAAQ,aAAa,eACrB,kBAAkB,WAAW,UAC7B,sBAEA,SAAS,gCACP,cACA,QACA,OACA,WACA,aAEF,cAAc,cACb,+BAA+B,OAAO"}
1
+ {"version":3,"file":"useSuspenseInfiniteQuery.d.cts","names":[],"sources":["../../src/useSuspenseInfiniteQuery.ts"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;iBAuGgB,yBACd,cACA,SAAS,cACT,QAAQ,aAAa,eACrB,kBAAkB,WAAW,UAC7B,sBAEA,SAAS,gCACP,cACA,QACA,OACA,WACA,aAEF,cAAc,cACb,+BAA+B,OAAO"}
@@ -1,6 +1,92 @@
1
1
  import { UseSuspenseInfiniteQueryOptions, UseSuspenseInfiniteQueryResult } from "./types.js";
2
2
  import { DefaultError, InfiniteData, QueryClient, QueryKey } from "@tanstack/query-core";
3
3
  //#region src/useSuspenseInfiniteQuery.d.ts
4
+ /**
5
+ * The options for `useSuspenseInfiniteQuery` are the same as for `useInfiniteQuery`, except for `throwOnError`,
6
+ * `enabled`, and `placeholderData`.
7
+ *
8
+ * Caveat: cancellation does not work.
9
+ *
10
+ * @remarks Multiple suspenseful query calls in the same component suspend serially, causing a request
11
+ * waterfall — each one blocks rendering until it resolves, so the next doesn't even start fetching until
12
+ * then. There's no way to parallelize multiple infinite queries under Suspense. Also keep in mind that
13
+ * imperative fetch calls, such as `fetchNextPage`, may interfere with the default refetch behavior,
14
+ * resulting in outdated data. Make sure to call these functions only in response to user actions, or add
15
+ * conditions like `hasNextPage && !isFetching`.
16
+ * @see {@link useInfiniteQuery} for the non-Suspense version of this hook.
17
+ * @param options - The {@link UseSuspenseInfiniteQueryOptions} to use — the same options as `useInfiniteQuery`, minus the ones listed above.
18
+ * @param queryClient - Use this to use a custom `QueryClient`. Otherwise, the one from the nearest context will
19
+ * be used.
20
+ * @returns The same object as `useInfiniteQuery`, except that `data` is guaranteed to be defined,
21
+ * `isPlaceholderData` is missing, and `status` is either `success` or `error` (with the derived flags set
22
+ * accordingly).
23
+ *
24
+ * @example
25
+ * The query error is thrown if a fetch fails and no cached data exists yet, so an error boundary is
26
+ * required around `<Suspense>`. A failed background refetch instead continues to render the cached data.
27
+ * Use {@link QueryErrorResetBoundary} to let the user retry after such an error:
28
+ * ```tsx
29
+ * import { Suspense } from 'react'
30
+ * import { ErrorBoundary } from 'react-error-boundary'
31
+ * import {
32
+ * QueryErrorResetBoundary,
33
+ * useSuspenseInfiniteQuery,
34
+ * } from '@tanstack/react-query'
35
+ *
36
+ * function Projects() {
37
+ * // `data` is guaranteed to be defined here — no `isPending` check needed.
38
+ * const { data, fetchNextPage, hasNextPage, isFetching, isFetchingNextPage } =
39
+ * useSuspenseInfiniteQuery({
40
+ * queryKey: ['projects'],
41
+ * queryFn: ({ pageParam }) => fetchProjects(pageParam),
42
+ * initialPageParam: 0,
43
+ * getNextPageParam: (lastPage) => lastPage.nextId,
44
+ * })
45
+ *
46
+ * return (
47
+ * <div>
48
+ * <ul>
49
+ * {data.pages.map((page) =>
50
+ * page.projects.map((project) => <li key={project.id}>{project.name}</li>),
51
+ * )}
52
+ * </ul>
53
+ * <button
54
+ * onClick={() => fetchNextPage()}
55
+ * disabled={!hasNextPage || isFetching}
56
+ * >
57
+ * {isFetchingNextPage
58
+ * ? 'Loading more...'
59
+ * : hasNextPage
60
+ * ? 'Load More'
61
+ * : 'Nothing more to load'}
62
+ * </button>
63
+ * </div>
64
+ * )
65
+ * }
66
+ *
67
+ * function App() {
68
+ * return (
69
+ * <QueryErrorResetBoundary>
70
+ * {({ reset }) => (
71
+ * <ErrorBoundary
72
+ * onReset={reset}
73
+ * fallbackRender={({ resetErrorBoundary }) => (
74
+ * <div>
75
+ * There was an error!
76
+ * <button onClick={() => resetErrorBoundary()}>Try again</button>
77
+ * </div>
78
+ * )}
79
+ * >
80
+ * <Suspense fallback={<h1>Loading projects...</h1>}>
81
+ * <Projects />
82
+ * </Suspense>
83
+ * </ErrorBoundary>
84
+ * )}
85
+ * </QueryErrorResetBoundary>
86
+ * )
87
+ * }
88
+ * ```
89
+ */
4
90
  declare function useSuspenseInfiniteQuery<TQueryFnData, TError = DefaultError, TData = InfiniteData<TQueryFnData>, TQueryKey extends QueryKey = QueryKey, TPageParam = unknown>(options: UseSuspenseInfiniteQueryOptions<TQueryFnData, TError, TData, TQueryKey, TPageParam>, queryClient?: QueryClient): UseSuspenseInfiniteQueryResult<TData, TError>;
5
91
  //#endregion
6
92
  export { useSuspenseInfiniteQuery };
@@ -1 +1 @@
1
- {"version":3,"file":"useSuspenseInfiniteQuery.d.ts","names":[],"sources":["../../src/useSuspenseInfiniteQuery.ts"],"mappings":";;;iBAiBgB,yBACd,cACA,SAAS,cACT,QAAQ,aAAa,eACrB,kBAAkB,WAAW,UAC7B,sBAEA,SAAS,gCACP,cACA,QACA,OACA,WACA,aAEF,cAAc,cACb,+BAA+B,OAAO"}
1
+ {"version":3,"file":"useSuspenseInfiniteQuery.d.ts","names":[],"sources":["../../src/useSuspenseInfiniteQuery.ts"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;iBAuGgB,yBACd,cACA,SAAS,cACT,QAAQ,aAAa,eACrB,kBAAkB,WAAW,UAC7B,sBAEA,SAAS,gCACP,cACA,QACA,OACA,WACA,aAEF,cAAc,cACb,+BAA+B,OAAO"}