@tanstack/react-query 5.102.8 → 5.103.1

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
@@ -40,19 +40,337 @@ type GetUseSuspenseQueryResult<T> = T extends {
40
40
  throwOnError?: ThrowOnError<any, infer TError, any, any>;
41
41
  } ? UseSuspenseQueryResult<TQueryFnData, unknown extends TError ? DefaultError : TError> : UseSuspenseQueryResult;
42
42
  /**
43
- * SuspenseQueriesOptions reducer recursively unwraps function arguments to infer/enforce type param
43
+ * The `queries` array accepted by `useSuspenseQueries`. Recursively unwraps each tuple element so every
44
+ * entry's `queryFn`/`select` are inferred individually, up to 20 elements. An opaque array (e.g. `unknown[]`)
45
+ * is returned as-is; a non-tuple array of a known element type, or a tuple past 20 elements, falls back to a
46
+ * single homogeneous {@link UseSuspenseQueryOptions} type.
47
+ *
48
+ * @template T - The type of the `queries` array as written at the call site.
49
+ * @template TResults - The internal accumulator that this type builds during recursion. It is not meant
50
+ * to be set explicitly.
51
+ * @template TDepth - The internal recursion-depth counter, checked against the 20-element limit. It is not
52
+ * meant to be set explicitly.
44
53
  */
45
54
  type SuspenseQueriesOptions<T extends Array<any>, TResults extends Array<any> = [], TDepth extends ReadonlyArray<number> = []> = TDepth['length'] extends MAXIMUM_DEPTH ? Array<UseSuspenseQueryOptions> : T extends [] ? [] : T extends [infer Head] ? [...TResults, GetUseSuspenseQueryOptions<Head>] : T extends [infer Head, ...infer Tails] ? SuspenseQueriesOptions<[...Tails], [...TResults, GetUseSuspenseQueryOptions<Head>], [...TDepth, 1]> : Array<unknown> extends T ? T : T extends Array<UseSuspenseQueryOptions<infer TQueryFnData, infer TError, infer TData, infer TQueryKey>> ? Array<UseSuspenseQueryOptions<TQueryFnData, TError, TData, TQueryKey>> : Array<UseSuspenseQueryOptions>;
46
55
  /**
47
- * SuspenseQueriesResults reducer recursively maps type param to results
56
+ * The result type returned by `useSuspenseQueries`, when no `combine` is provided. Mirrors
57
+ * {@link SuspenseQueriesOptions}: each tuple element's result type is inferred individually, up to 20 elements.
58
+ * A non-tuple array is mapped per-element instead, still inferring each entry individually; only past 20
59
+ * elements does this fall back to a single homogeneous {@link UseSuspenseQueryResult} type.
60
+ *
61
+ * @template T - The type of the `queries` array, as inferred by {@link SuspenseQueriesOptions}.
62
+ * @template TResults - The internal accumulator that this type builds during recursion. It is not meant
63
+ * to be set explicitly.
64
+ * @template TDepth - The internal recursion-depth counter, checked against the 20-element limit. It is not
65
+ * meant to be set explicitly.
48
66
  */
49
67
  type SuspenseQueriesResults<T extends Array<any>, TResults extends Array<any> = [], TDepth extends ReadonlyArray<number> = []> = TDepth['length'] extends MAXIMUM_DEPTH ? Array<UseSuspenseQueryResult> : T extends [] ? [] : T extends [infer Head] ? [...TResults, GetUseSuspenseQueryResult<Head>] : T extends [infer Head, ...infer Tails] ? SuspenseQueriesResults<[...Tails], [...TResults, GetUseSuspenseQueryResult<Head>], [...TDepth, 1]> : { [K in keyof T]: GetUseSuspenseQueryResult<T[K]>; };
68
+ /**
69
+ * The options for `useSuspenseQueries` are the same as for `useQueries`, except that the top-level `subscribed`
70
+ * option isn't supported, and each `query` can't have `throwOnError`, `enabled`, or `placeholderData`.
71
+ *
72
+ * @param options - The `queries` array to run in Suspense, and an optional `combine` function.
73
+ * @param queryClient - Use this to provide a custom `QueryClient`. Otherwise, the one from the nearest context
74
+ * will be used.
75
+ * @returns The same structure as `useQueries`, except that for each `query`, `data` is guaranteed to be
76
+ * defined, `isPlaceholderData` is missing, and `status` is either `success` or `error` (with the derived
77
+ * flags set accordingly).
78
+ *
79
+ * Caveat: the component will only re-mount after all queries have finished loading. Hence, if a query has gone
80
+ * stale in the time it took for all the queries to complete, it will be fetched again at re-mount. To avoid
81
+ * this, make sure to set a high enough `staleTime`. Cancellation does not work.
82
+ *
83
+ * @example
84
+ * The query error is thrown if a fetch fails and no cached data exists yet, so an error boundary is
85
+ * required around `<Suspense>`. A failed background refetch instead continues to render the cached data.
86
+ * Use {@link QueryErrorResetBoundary} to let the user retry after such an error:
87
+ * ```tsx
88
+ * import { Suspense } from 'react'
89
+ * import { ErrorBoundary } from 'react-error-boundary'
90
+ * import {
91
+ * QueryErrorResetBoundary,
92
+ * useSuspenseQueries,
93
+ * } from '@tanstack/react-query'
94
+ *
95
+ * function Posts({ ids }: { ids: Array<number> }) {
96
+ * // Every result is guaranteed to be defined — no per-query `isPending` check needed.
97
+ * const postQueries = useSuspenseQueries({
98
+ * queries: ids.map((id) => ({
99
+ * queryKey: ['post', id],
100
+ * queryFn: () => fetchPost(id),
101
+ * })),
102
+ * })
103
+ *
104
+ * return (
105
+ * <ul>
106
+ * {postQueries.map((query) => (
107
+ * <li key={query.data.id}>{query.data.title}</li>
108
+ * ))}
109
+ * </ul>
110
+ * )
111
+ * }
112
+ *
113
+ * function App() {
114
+ * return (
115
+ * <QueryErrorResetBoundary>
116
+ * {({ reset }) => (
117
+ * <ErrorBoundary
118
+ * onReset={reset}
119
+ * fallbackRender={({ resetErrorBoundary }) => (
120
+ * <div>
121
+ * There was an error!
122
+ * <button onClick={() => resetErrorBoundary()}>Try again</button>
123
+ * </div>
124
+ * )}
125
+ * >
126
+ * <Suspense fallback={<h1>Loading posts...</h1>}>
127
+ * <Posts ids={[1, 2, 3]} />
128
+ * </Suspense>
129
+ * </ErrorBoundary>
130
+ * )}
131
+ * </QueryErrorResetBoundary>
132
+ * )
133
+ * }
134
+ * ```
135
+ *
136
+ * @example
137
+ * Several different queries — use `useSuspenseQueries` instead of multiple `useSuspenseQuery` calls, so
138
+ * they fetch in parallel rather than suspending one after another:
139
+ * ```tsx
140
+ * import { Suspense } from 'react'
141
+ * import { ErrorBoundary } from 'react-error-boundary'
142
+ * import {
143
+ * QueryErrorResetBoundary,
144
+ * useSuspenseQueries,
145
+ * } from '@tanstack/react-query'
146
+ *
147
+ * function Dashboard() {
148
+ * const [usersQuery, teamsQuery, projectsQuery] = useSuspenseQueries({
149
+ * queries: [
150
+ * { queryKey: ['users'], queryFn: fetchUsers },
151
+ * { queryKey: ['teams'], queryFn: fetchTeams },
152
+ * { queryKey: ['projects'], queryFn: fetchProjects },
153
+ * ],
154
+ * })
155
+ *
156
+ * return (
157
+ * <div>
158
+ * <UserList users={usersQuery.data} />
159
+ * <TeamList teams={teamsQuery.data} />
160
+ * <ProjectList projects={projectsQuery.data} />
161
+ * </div>
162
+ * )
163
+ * }
164
+ *
165
+ * function App() {
166
+ * return (
167
+ * <QueryErrorResetBoundary>
168
+ * {({ reset }) => (
169
+ * <ErrorBoundary
170
+ * onReset={reset}
171
+ * fallbackRender={({ resetErrorBoundary }) => (
172
+ * <div>
173
+ * There was an error!
174
+ * <button onClick={() => resetErrorBoundary()}>Try again</button>
175
+ * </div>
176
+ * )}
177
+ * >
178
+ * <Suspense fallback={<h1>Loading dashboard...</h1>}>
179
+ * <Dashboard />
180
+ * </Suspense>
181
+ * </ErrorBoundary>
182
+ * )}
183
+ * </QueryErrorResetBoundary>
184
+ * )
185
+ * }
186
+ * ```
187
+ *
188
+ * @example
189
+ * `combine`s the results into a single boolean, so `Refresh` only re-renders when that boolean changes,
190
+ * not on every individual query update. This overload is the only one that accepts `combine`:
191
+ * ```tsx
192
+ * import { Suspense } from 'react'
193
+ * import { ErrorBoundary } from 'react-error-boundary'
194
+ * import {
195
+ * QueryErrorResetBoundary,
196
+ * useSuspenseQueries,
197
+ * } from '@tanstack/react-query'
198
+ *
199
+ * function Refresh() {
200
+ * const anyFetching = useSuspenseQueries({
201
+ * queries: [
202
+ * { queryKey: ['users'], queryFn: fetchUsers },
203
+ * { queryKey: ['teams'], queryFn: fetchTeams },
204
+ * ],
205
+ * combine: (results) => results.some((result) => result.isFetching),
206
+ * })
207
+ *
208
+ * return anyFetching ? <span>Refreshing…</span> : null
209
+ * }
210
+ *
211
+ * function App() {
212
+ * return (
213
+ * <QueryErrorResetBoundary>
214
+ * {({ reset }) => (
215
+ * <ErrorBoundary
216
+ * onReset={reset}
217
+ * fallbackRender={({ resetErrorBoundary }) => (
218
+ * <div>
219
+ * There was an error!
220
+ * <button onClick={() => resetErrorBoundary()}>Try again</button>
221
+ * </div>
222
+ * )}
223
+ * >
224
+ * <Suspense fallback={<h1>Loading dashboard...</h1>}>
225
+ * <Refresh />
226
+ * </Suspense>
227
+ * </ErrorBoundary>
228
+ * )}
229
+ * </QueryErrorResetBoundary>
230
+ * )
231
+ * }
232
+ * ```
233
+ */
50
234
  declare function useSuspenseQueries<T extends Array<any>, TCombinedResult = SuspenseQueriesResults<T>>(options: {
235
+ /**
236
+ * An array with query option objects identical to `useSuspenseQuery`.
237
+ */
51
238
  queries: readonly [...SuspenseQueriesOptions<T>] | readonly [...{ [K in keyof T]: GetUseSuspenseQueryOptions<T[K]>; }];
239
+ /**
240
+ * Use this to combine the results of the queries into a single value. The result will be structurally
241
+ * shared to be as referentially stable as possible.
242
+ */
52
243
  combine?: (result: SuspenseQueriesResults<T>) => TCombinedResult;
53
244
  }, queryClient?: QueryClient): TCombinedResult;
245
+ /**
246
+ * The options for `useSuspenseQueries` are the same as for `useQueries`, except that the top-level `subscribed`
247
+ * option isn't supported, and each `query` can't have `throwOnError`, `enabled`, or `placeholderData`.
248
+ *
249
+ * @param options - The `queries` array to run in Suspense, and an optional `combine` function.
250
+ * @param queryClient - Use this to provide a custom `QueryClient`. Otherwise, the one from the nearest context
251
+ * will be used.
252
+ * @returns The same structure as `useQueries`, except that for each `query`, `data` is guaranteed to be
253
+ * defined, `isPlaceholderData` is missing, and `status` is either `success` or `error` (with the derived
254
+ * flags set accordingly).
255
+ *
256
+ * Caveat: the component will only re-mount after all queries have finished loading. Hence, if a query has gone
257
+ * stale in the time it took for all the queries to complete, it will be fetched again at re-mount. To avoid
258
+ * this, make sure to set a high enough `staleTime`. Cancellation does not work.
259
+ *
260
+ * @example
261
+ * The query error is thrown if a fetch fails and no cached data exists yet, so an error boundary is
262
+ * required around `<Suspense>`. A failed background refetch instead continues to render the cached data.
263
+ * Use {@link QueryErrorResetBoundary} to let the user retry after such an error:
264
+ * ```tsx
265
+ * import { Suspense } from 'react'
266
+ * import { ErrorBoundary } from 'react-error-boundary'
267
+ * import {
268
+ * QueryErrorResetBoundary,
269
+ * useSuspenseQueries,
270
+ * } from '@tanstack/react-query'
271
+ *
272
+ * function Posts({ ids }: { ids: Array<number> }) {
273
+ * // Every result is guaranteed to be defined — no per-query `isPending` check needed.
274
+ * const postQueries = useSuspenseQueries({
275
+ * queries: ids.map((id) => ({
276
+ * queryKey: ['post', id],
277
+ * queryFn: () => fetchPost(id),
278
+ * })),
279
+ * })
280
+ *
281
+ * return (
282
+ * <ul>
283
+ * {postQueries.map((query) => (
284
+ * <li key={query.data.id}>{query.data.title}</li>
285
+ * ))}
286
+ * </ul>
287
+ * )
288
+ * }
289
+ *
290
+ * function App() {
291
+ * return (
292
+ * <QueryErrorResetBoundary>
293
+ * {({ reset }) => (
294
+ * <ErrorBoundary
295
+ * onReset={reset}
296
+ * fallbackRender={({ resetErrorBoundary }) => (
297
+ * <div>
298
+ * There was an error!
299
+ * <button onClick={() => resetErrorBoundary()}>Try again</button>
300
+ * </div>
301
+ * )}
302
+ * >
303
+ * <Suspense fallback={<h1>Loading posts...</h1>}>
304
+ * <Posts ids={[1, 2, 3]} />
305
+ * </Suspense>
306
+ * </ErrorBoundary>
307
+ * )}
308
+ * </QueryErrorResetBoundary>
309
+ * )
310
+ * }
311
+ * ```
312
+ *
313
+ * @example
314
+ * Several different queries — use `useSuspenseQueries` instead of multiple `useSuspenseQuery` calls, so
315
+ * they fetch in parallel rather than suspending one after another:
316
+ * ```tsx
317
+ * import { Suspense } from 'react'
318
+ * import { ErrorBoundary } from 'react-error-boundary'
319
+ * import {
320
+ * QueryErrorResetBoundary,
321
+ * useSuspenseQueries,
322
+ * } from '@tanstack/react-query'
323
+ *
324
+ * function Dashboard() {
325
+ * const [usersQuery, teamsQuery, projectsQuery] = useSuspenseQueries({
326
+ * queries: [
327
+ * { queryKey: ['users'], queryFn: fetchUsers },
328
+ * { queryKey: ['teams'], queryFn: fetchTeams },
329
+ * { queryKey: ['projects'], queryFn: fetchProjects },
330
+ * ],
331
+ * })
332
+ *
333
+ * return (
334
+ * <div>
335
+ * <UserList users={usersQuery.data} />
336
+ * <TeamList teams={teamsQuery.data} />
337
+ * <ProjectList projects={projectsQuery.data} />
338
+ * </div>
339
+ * )
340
+ * }
341
+ *
342
+ * function App() {
343
+ * return (
344
+ * <QueryErrorResetBoundary>
345
+ * {({ reset }) => (
346
+ * <ErrorBoundary
347
+ * onReset={reset}
348
+ * fallbackRender={({ resetErrorBoundary }) => (
349
+ * <div>
350
+ * There was an error!
351
+ * <button onClick={() => resetErrorBoundary()}>Try again</button>
352
+ * </div>
353
+ * )}
354
+ * >
355
+ * <Suspense fallback={<h1>Loading dashboard...</h1>}>
356
+ * <Dashboard />
357
+ * </Suspense>
358
+ * </ErrorBoundary>
359
+ * )}
360
+ * </QueryErrorResetBoundary>
361
+ * )
362
+ * }
363
+ * ```
364
+ */
54
365
  declare function useSuspenseQueries<T extends Array<any>, TCombinedResult = SuspenseQueriesResults<T>>(options: {
366
+ /**
367
+ * An array with query option objects identical to `useSuspenseQuery`.
368
+ */
55
369
  queries: readonly [...SuspenseQueriesOptions<T>];
370
+ /**
371
+ * Use this to combine the results of the queries into a single value. The result will be structurally
372
+ * shared to be as referentially stable as possible.
373
+ */
56
374
  combine?: (result: SuspenseQueriesResults<T>) => TCombinedResult;
57
375
  }, queryClient?: QueryClient): TCombinedResult;
58
376
  //#endregion
@@ -1 +1 @@
1
- {"version":3,"file":"useSuspenseQueries.d.cts","names":[],"sources":["../../src/useSuspenseQueries.ts"],"mappings":";;;KAaK;KAGA;KAEA,2BAA2B,KAE9B;EACE,mBAAmB;EACnB,cAAc;EACd,YAAY;IAEV,wBAAwB,cAAc,QAAQ,SAC9C;EAAY,mBAAmB;EAAc,cAAc;IACzD,wBAAwB,cAAc,UACtC;EAAY,YAAY;EAAO,cAAc;IAC3C,iCAAiC,QAAQ,SAEzC,iBAAiB,oBAAoB,cAAc,SACjD,wBAAwB,cAAc,QAAQ,SAC9C,iBAAiB,oBAAoB,UACnC,wBAAwB,cAAc,UACtC,iBAAiB,gBACf,wBAAwB,gBAExB;EACI,UACI,oBAAoB,oBAAoB,aACxC;EACJ,UAAU,oBAAoB;EAC9B,eAAe,wBAAwB;IAEzC,wBACE,cACA,QACA,OACA,aAEF;EACI,UACI,oBAAoB,oBAAoB,aACxC;EACJ,eAAe,wBAAwB;IAEzC,wBACE,cACA,QACA,cACA,aAGF;KAEf,0BAA0B,KAE7B;EAAY;EAAkB,cAAc;EAAQ,YAAY;IAC5D,uBAAuB,OAAO,UAC9B;EAAY,mBAAmB;EAAc,cAAc;IACzD,uBAAuB,cAAc,UACrC;EAAY,YAAY;EAAO,cAAc;IAC3C,uBAAuB,OAAO,UAE9B,sBAAsB,cAAc,SAClC,uBAAuB,OAAO,UAC9B,iBAAiB,oBAAoB,UACnC,uBAAuB,cAAc,UACrC,iBAAiB,gBACf,uBAAuB,gBAEvB;EACI,UACI,oBAAoB,qBACpB;EACJ,UAAU,oBAAoB;EAC9B,eAAe,wBAAwB;IAEzC,uCACkB,QAAQ,eAAe,uBACvB,SAAS,eAAe,UAE1C;EACI,UACI,oBAAoB,qBACpB;EACJ,eAAe,wBAAwB;IAEzC,uBACE,8BACgB,SAAS,eAAe,UAG1C;;;;KAKR,uBACV,UAAU,YACV,iBAAiB,iBACjB,eAAe,8BACb,yBAAyB,gBACzB,MAAM,2BACN,oBAEE,iBAAiB,YACX,UAAU,2BAA2B,SACzC,iBAAiB,eAAe,SAC9B,2BACM,YACA,UAAU,2BAA2B,YACrC,cAEN,uBAAuB,IACrB,IAGA,UAAU,MACN,8BACQ,oBACA,cACA,aACA,cAGV,MACE,wBAAwB,cAAc,QAAQ,OAAO,cAGvD,MAAM;;;;KAKR,uBACV,UAAU,YACV,iBAAiB,iBACjB,eAAe,8BACb,yBAAyB,gBACzB,MAAM,0BACN,oBAEE,iBAAiB,YACX,UAAU,0BAA0B,SACxC,iBAAiB,eAAe,SAC9B,2BACM,YACA,UAAU,0BAA0B,YACpC,iBAEH,WAAW,IAAI,0BAA0B,EAAE;iBAExC,mBACd,UAAU,YACV,kBAAkB,uBAAuB,IAEzC;EACE,sBACiB,uBAAuB,sBACpB,WAAW,IAAI,2BAA2B,EAAE;EAChE,WAAW,QAAQ,uBAAuB,OAAO;GAEnD,cAAc,cACb;iBAEa,mBACd,UAAU,YACV,kBAAkB,uBAAuB,IAEzC;EACE,sBAAsB,uBAAuB;EAC7C,WAAW,QAAQ,uBAAuB,OAAO;GAEnD,cAAc,cACb"}
1
+ {"version":3,"file":"useSuspenseQueries.d.cts","names":[],"sources":["../../src/useSuspenseQueries.ts"],"mappings":";;;KAaK;KAGA;KAEA,2BAA2B,KAE9B;EACE,mBAAmB;EACnB,cAAc;EACd,YAAY;IAEV,wBAAwB,cAAc,QAAQ,SAC9C;EAAY,mBAAmB;EAAc,cAAc;IACzD,wBAAwB,cAAc,UACtC;EAAY,YAAY;EAAO,cAAc;IAC3C,iCAAiC,QAAQ,SAEzC,iBAAiB,oBAAoB,cAAc,SACjD,wBAAwB,cAAc,QAAQ,SAC9C,iBAAiB,oBAAoB,UACnC,wBAAwB,cAAc,UACtC,iBAAiB,gBACf,wBAAwB,gBAExB;EACI,UACI,oBAAoB,oBAAoB,aACxC;EACJ,UAAU,oBAAoB;EAC9B,eAAe,wBAAwB;IAEzC,wBACE,cACA,QACA,OACA,aAEF;EACI,UACI,oBAAoB,oBAAoB,aACxC;EACJ,eAAe,wBAAwB;IAEzC,wBACE,cACA,QACA,cACA,aAGF;KAEf,0BAA0B,KAE7B;EAAY;EAAkB,cAAc;EAAQ,YAAY;IAC5D,uBAAuB,OAAO,UAC9B;EAAY,mBAAmB;EAAc,cAAc;IACzD,uBAAuB,cAAc,UACrC;EAAY,YAAY;EAAO,cAAc;IAC3C,uBAAuB,OAAO,UAE9B,sBAAsB,cAAc,SAClC,uBAAuB,OAAO,UAC9B,iBAAiB,oBAAoB,UACnC,uBAAuB,cAAc,UACrC,iBAAiB,gBACf,uBAAuB,gBAEvB;EACI,UACI,oBAAoB,qBACpB;EACJ,UAAU,oBAAoB;EAC9B,eAAe,wBAAwB;IAEzC,uCACkB,QAAQ,eAAe,uBACvB,SAAS,eAAe,UAE1C;EACI,UACI,oBAAoB,qBACpB;EACJ,eAAe,wBAAwB;IAEzC,uBACE,8BACgB,SAAS,eAAe,UAG1C;;;;;;;;;;;;;KAcR,uBACV,UAAU,YACV,iBAAiB,iBACjB,eAAe,8BACb,yBAAyB,gBACzB,MAAM,2BACN,oBAEE,iBAAiB,YACX,UAAU,2BAA2B,SACzC,iBAAiB,eAAe,SAC9B,2BACM,YACA,UAAU,2BAA2B,YACrC,cAEN,uBAAuB,IACrB,IAGA,UAAU,MACN,8BACQ,oBACA,cACA,aACA,cAGV,MACE,wBAAwB,cAAc,QAAQ,OAAO,cAGvD,MAAM;;;;;;;;;;;;;KAcR,uBACV,UAAU,YACV,iBAAiB,iBACjB,eAAe,8BACb,yBAAyB,gBACzB,MAAM,0BACN,oBAEE,iBAAiB,YACX,UAAU,0BAA0B,SACxC,iBAAiB,eAAe,SAC9B,2BACM,YACA,UAAU,0BAA0B,YACpC,iBAEH,WAAW,IAAI,0BAA0B,EAAE;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;iBAwKxC,mBACd,UAAU,YACV,kBAAkB,uBAAuB,IAEzC;;;;EAIE,sBACiB,uBAAuB,sBACpB,WAAW,IAAI,2BAA2B,EAAE;;;;;EAKhE,WAAW,QAAQ,uBAAuB,OAAO;GAEnD,cAAc,cACb;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;iBA0Ha,mBACd,UAAU,YACV,kBAAkB,uBAAuB,IAEzC;;;;EAIE,sBAAsB,uBAAuB;;;;;EAK7C,WAAW,QAAQ,uBAAuB,OAAO;GAEnD,cAAc,cACb"}
@@ -40,19 +40,337 @@ type GetUseSuspenseQueryResult<T> = T extends {
40
40
  throwOnError?: ThrowOnError<any, infer TError, any, any>;
41
41
  } ? UseSuspenseQueryResult<TQueryFnData, unknown extends TError ? DefaultError : TError> : UseSuspenseQueryResult;
42
42
  /**
43
- * SuspenseQueriesOptions reducer recursively unwraps function arguments to infer/enforce type param
43
+ * The `queries` array accepted by `useSuspenseQueries`. Recursively unwraps each tuple element so every
44
+ * entry's `queryFn`/`select` are inferred individually, up to 20 elements. An opaque array (e.g. `unknown[]`)
45
+ * is returned as-is; a non-tuple array of a known element type, or a tuple past 20 elements, falls back to a
46
+ * single homogeneous {@link UseSuspenseQueryOptions} type.
47
+ *
48
+ * @template T - The type of the `queries` array as written at the call site.
49
+ * @template TResults - The internal accumulator that this type builds during recursion. It is not meant
50
+ * to be set explicitly.
51
+ * @template TDepth - The internal recursion-depth counter, checked against the 20-element limit. It is not
52
+ * meant to be set explicitly.
44
53
  */
45
54
  type SuspenseQueriesOptions<T extends Array<any>, TResults extends Array<any> = [], TDepth extends ReadonlyArray<number> = []> = TDepth['length'] extends MAXIMUM_DEPTH ? Array<UseSuspenseQueryOptions> : T extends [] ? [] : T extends [infer Head] ? [...TResults, GetUseSuspenseQueryOptions<Head>] : T extends [infer Head, ...infer Tails] ? SuspenseQueriesOptions<[...Tails], [...TResults, GetUseSuspenseQueryOptions<Head>], [...TDepth, 1]> : Array<unknown> extends T ? T : T extends Array<UseSuspenseQueryOptions<infer TQueryFnData, infer TError, infer TData, infer TQueryKey>> ? Array<UseSuspenseQueryOptions<TQueryFnData, TError, TData, TQueryKey>> : Array<UseSuspenseQueryOptions>;
46
55
  /**
47
- * SuspenseQueriesResults reducer recursively maps type param to results
56
+ * The result type returned by `useSuspenseQueries`, when no `combine` is provided. Mirrors
57
+ * {@link SuspenseQueriesOptions}: each tuple element's result type is inferred individually, up to 20 elements.
58
+ * A non-tuple array is mapped per-element instead, still inferring each entry individually; only past 20
59
+ * elements does this fall back to a single homogeneous {@link UseSuspenseQueryResult} type.
60
+ *
61
+ * @template T - The type of the `queries` array, as inferred by {@link SuspenseQueriesOptions}.
62
+ * @template TResults - The internal accumulator that this type builds during recursion. It is not meant
63
+ * to be set explicitly.
64
+ * @template TDepth - The internal recursion-depth counter, checked against the 20-element limit. It is not
65
+ * meant to be set explicitly.
48
66
  */
49
67
  type SuspenseQueriesResults<T extends Array<any>, TResults extends Array<any> = [], TDepth extends ReadonlyArray<number> = []> = TDepth['length'] extends MAXIMUM_DEPTH ? Array<UseSuspenseQueryResult> : T extends [] ? [] : T extends [infer Head] ? [...TResults, GetUseSuspenseQueryResult<Head>] : T extends [infer Head, ...infer Tails] ? SuspenseQueriesResults<[...Tails], [...TResults, GetUseSuspenseQueryResult<Head>], [...TDepth, 1]> : { [K in keyof T]: GetUseSuspenseQueryResult<T[K]>; };
68
+ /**
69
+ * The options for `useSuspenseQueries` are the same as for `useQueries`, except that the top-level `subscribed`
70
+ * option isn't supported, and each `query` can't have `throwOnError`, `enabled`, or `placeholderData`.
71
+ *
72
+ * @param options - The `queries` array to run in Suspense, and an optional `combine` function.
73
+ * @param queryClient - Use this to provide a custom `QueryClient`. Otherwise, the one from the nearest context
74
+ * will be used.
75
+ * @returns The same structure as `useQueries`, except that for each `query`, `data` is guaranteed to be
76
+ * defined, `isPlaceholderData` is missing, and `status` is either `success` or `error` (with the derived
77
+ * flags set accordingly).
78
+ *
79
+ * Caveat: the component will only re-mount after all queries have finished loading. Hence, if a query has gone
80
+ * stale in the time it took for all the queries to complete, it will be fetched again at re-mount. To avoid
81
+ * this, make sure to set a high enough `staleTime`. Cancellation does not work.
82
+ *
83
+ * @example
84
+ * The query error is thrown if a fetch fails and no cached data exists yet, so an error boundary is
85
+ * required around `<Suspense>`. A failed background refetch instead continues to render the cached data.
86
+ * Use {@link QueryErrorResetBoundary} to let the user retry after such an error:
87
+ * ```tsx
88
+ * import { Suspense } from 'react'
89
+ * import { ErrorBoundary } from 'react-error-boundary'
90
+ * import {
91
+ * QueryErrorResetBoundary,
92
+ * useSuspenseQueries,
93
+ * } from '@tanstack/react-query'
94
+ *
95
+ * function Posts({ ids }: { ids: Array<number> }) {
96
+ * // Every result is guaranteed to be defined — no per-query `isPending` check needed.
97
+ * const postQueries = useSuspenseQueries({
98
+ * queries: ids.map((id) => ({
99
+ * queryKey: ['post', id],
100
+ * queryFn: () => fetchPost(id),
101
+ * })),
102
+ * })
103
+ *
104
+ * return (
105
+ * <ul>
106
+ * {postQueries.map((query) => (
107
+ * <li key={query.data.id}>{query.data.title}</li>
108
+ * ))}
109
+ * </ul>
110
+ * )
111
+ * }
112
+ *
113
+ * function App() {
114
+ * return (
115
+ * <QueryErrorResetBoundary>
116
+ * {({ reset }) => (
117
+ * <ErrorBoundary
118
+ * onReset={reset}
119
+ * fallbackRender={({ resetErrorBoundary }) => (
120
+ * <div>
121
+ * There was an error!
122
+ * <button onClick={() => resetErrorBoundary()}>Try again</button>
123
+ * </div>
124
+ * )}
125
+ * >
126
+ * <Suspense fallback={<h1>Loading posts...</h1>}>
127
+ * <Posts ids={[1, 2, 3]} />
128
+ * </Suspense>
129
+ * </ErrorBoundary>
130
+ * )}
131
+ * </QueryErrorResetBoundary>
132
+ * )
133
+ * }
134
+ * ```
135
+ *
136
+ * @example
137
+ * Several different queries — use `useSuspenseQueries` instead of multiple `useSuspenseQuery` calls, so
138
+ * they fetch in parallel rather than suspending one after another:
139
+ * ```tsx
140
+ * import { Suspense } from 'react'
141
+ * import { ErrorBoundary } from 'react-error-boundary'
142
+ * import {
143
+ * QueryErrorResetBoundary,
144
+ * useSuspenseQueries,
145
+ * } from '@tanstack/react-query'
146
+ *
147
+ * function Dashboard() {
148
+ * const [usersQuery, teamsQuery, projectsQuery] = useSuspenseQueries({
149
+ * queries: [
150
+ * { queryKey: ['users'], queryFn: fetchUsers },
151
+ * { queryKey: ['teams'], queryFn: fetchTeams },
152
+ * { queryKey: ['projects'], queryFn: fetchProjects },
153
+ * ],
154
+ * })
155
+ *
156
+ * return (
157
+ * <div>
158
+ * <UserList users={usersQuery.data} />
159
+ * <TeamList teams={teamsQuery.data} />
160
+ * <ProjectList projects={projectsQuery.data} />
161
+ * </div>
162
+ * )
163
+ * }
164
+ *
165
+ * function App() {
166
+ * return (
167
+ * <QueryErrorResetBoundary>
168
+ * {({ reset }) => (
169
+ * <ErrorBoundary
170
+ * onReset={reset}
171
+ * fallbackRender={({ resetErrorBoundary }) => (
172
+ * <div>
173
+ * There was an error!
174
+ * <button onClick={() => resetErrorBoundary()}>Try again</button>
175
+ * </div>
176
+ * )}
177
+ * >
178
+ * <Suspense fallback={<h1>Loading dashboard...</h1>}>
179
+ * <Dashboard />
180
+ * </Suspense>
181
+ * </ErrorBoundary>
182
+ * )}
183
+ * </QueryErrorResetBoundary>
184
+ * )
185
+ * }
186
+ * ```
187
+ *
188
+ * @example
189
+ * `combine`s the results into a single boolean, so `Refresh` only re-renders when that boolean changes,
190
+ * not on every individual query update. This overload is the only one that accepts `combine`:
191
+ * ```tsx
192
+ * import { Suspense } from 'react'
193
+ * import { ErrorBoundary } from 'react-error-boundary'
194
+ * import {
195
+ * QueryErrorResetBoundary,
196
+ * useSuspenseQueries,
197
+ * } from '@tanstack/react-query'
198
+ *
199
+ * function Refresh() {
200
+ * const anyFetching = useSuspenseQueries({
201
+ * queries: [
202
+ * { queryKey: ['users'], queryFn: fetchUsers },
203
+ * { queryKey: ['teams'], queryFn: fetchTeams },
204
+ * ],
205
+ * combine: (results) => results.some((result) => result.isFetching),
206
+ * })
207
+ *
208
+ * return anyFetching ? <span>Refreshing…</span> : null
209
+ * }
210
+ *
211
+ * function App() {
212
+ * return (
213
+ * <QueryErrorResetBoundary>
214
+ * {({ reset }) => (
215
+ * <ErrorBoundary
216
+ * onReset={reset}
217
+ * fallbackRender={({ resetErrorBoundary }) => (
218
+ * <div>
219
+ * There was an error!
220
+ * <button onClick={() => resetErrorBoundary()}>Try again</button>
221
+ * </div>
222
+ * )}
223
+ * >
224
+ * <Suspense fallback={<h1>Loading dashboard...</h1>}>
225
+ * <Refresh />
226
+ * </Suspense>
227
+ * </ErrorBoundary>
228
+ * )}
229
+ * </QueryErrorResetBoundary>
230
+ * )
231
+ * }
232
+ * ```
233
+ */
50
234
  declare function useSuspenseQueries<T extends Array<any>, TCombinedResult = SuspenseQueriesResults<T>>(options: {
235
+ /**
236
+ * An array with query option objects identical to `useSuspenseQuery`.
237
+ */
51
238
  queries: readonly [...SuspenseQueriesOptions<T>] | readonly [...{ [K in keyof T]: GetUseSuspenseQueryOptions<T[K]>; }];
239
+ /**
240
+ * Use this to combine the results of the queries into a single value. The result will be structurally
241
+ * shared to be as referentially stable as possible.
242
+ */
52
243
  combine?: (result: SuspenseQueriesResults<T>) => TCombinedResult;
53
244
  }, queryClient?: QueryClient): TCombinedResult;
245
+ /**
246
+ * The options for `useSuspenseQueries` are the same as for `useQueries`, except that the top-level `subscribed`
247
+ * option isn't supported, and each `query` can't have `throwOnError`, `enabled`, or `placeholderData`.
248
+ *
249
+ * @param options - The `queries` array to run in Suspense, and an optional `combine` function.
250
+ * @param queryClient - Use this to provide a custom `QueryClient`. Otherwise, the one from the nearest context
251
+ * will be used.
252
+ * @returns The same structure as `useQueries`, except that for each `query`, `data` is guaranteed to be
253
+ * defined, `isPlaceholderData` is missing, and `status` is either `success` or `error` (with the derived
254
+ * flags set accordingly).
255
+ *
256
+ * Caveat: the component will only re-mount after all queries have finished loading. Hence, if a query has gone
257
+ * stale in the time it took for all the queries to complete, it will be fetched again at re-mount. To avoid
258
+ * this, make sure to set a high enough `staleTime`. Cancellation does not work.
259
+ *
260
+ * @example
261
+ * The query error is thrown if a fetch fails and no cached data exists yet, so an error boundary is
262
+ * required around `<Suspense>`. A failed background refetch instead continues to render the cached data.
263
+ * Use {@link QueryErrorResetBoundary} to let the user retry after such an error:
264
+ * ```tsx
265
+ * import { Suspense } from 'react'
266
+ * import { ErrorBoundary } from 'react-error-boundary'
267
+ * import {
268
+ * QueryErrorResetBoundary,
269
+ * useSuspenseQueries,
270
+ * } from '@tanstack/react-query'
271
+ *
272
+ * function Posts({ ids }: { ids: Array<number> }) {
273
+ * // Every result is guaranteed to be defined — no per-query `isPending` check needed.
274
+ * const postQueries = useSuspenseQueries({
275
+ * queries: ids.map((id) => ({
276
+ * queryKey: ['post', id],
277
+ * queryFn: () => fetchPost(id),
278
+ * })),
279
+ * })
280
+ *
281
+ * return (
282
+ * <ul>
283
+ * {postQueries.map((query) => (
284
+ * <li key={query.data.id}>{query.data.title}</li>
285
+ * ))}
286
+ * </ul>
287
+ * )
288
+ * }
289
+ *
290
+ * function App() {
291
+ * return (
292
+ * <QueryErrorResetBoundary>
293
+ * {({ reset }) => (
294
+ * <ErrorBoundary
295
+ * onReset={reset}
296
+ * fallbackRender={({ resetErrorBoundary }) => (
297
+ * <div>
298
+ * There was an error!
299
+ * <button onClick={() => resetErrorBoundary()}>Try again</button>
300
+ * </div>
301
+ * )}
302
+ * >
303
+ * <Suspense fallback={<h1>Loading posts...</h1>}>
304
+ * <Posts ids={[1, 2, 3]} />
305
+ * </Suspense>
306
+ * </ErrorBoundary>
307
+ * )}
308
+ * </QueryErrorResetBoundary>
309
+ * )
310
+ * }
311
+ * ```
312
+ *
313
+ * @example
314
+ * Several different queries — use `useSuspenseQueries` instead of multiple `useSuspenseQuery` calls, so
315
+ * they fetch in parallel rather than suspending one after another:
316
+ * ```tsx
317
+ * import { Suspense } from 'react'
318
+ * import { ErrorBoundary } from 'react-error-boundary'
319
+ * import {
320
+ * QueryErrorResetBoundary,
321
+ * useSuspenseQueries,
322
+ * } from '@tanstack/react-query'
323
+ *
324
+ * function Dashboard() {
325
+ * const [usersQuery, teamsQuery, projectsQuery] = useSuspenseQueries({
326
+ * queries: [
327
+ * { queryKey: ['users'], queryFn: fetchUsers },
328
+ * { queryKey: ['teams'], queryFn: fetchTeams },
329
+ * { queryKey: ['projects'], queryFn: fetchProjects },
330
+ * ],
331
+ * })
332
+ *
333
+ * return (
334
+ * <div>
335
+ * <UserList users={usersQuery.data} />
336
+ * <TeamList teams={teamsQuery.data} />
337
+ * <ProjectList projects={projectsQuery.data} />
338
+ * </div>
339
+ * )
340
+ * }
341
+ *
342
+ * function App() {
343
+ * return (
344
+ * <QueryErrorResetBoundary>
345
+ * {({ reset }) => (
346
+ * <ErrorBoundary
347
+ * onReset={reset}
348
+ * fallbackRender={({ resetErrorBoundary }) => (
349
+ * <div>
350
+ * There was an error!
351
+ * <button onClick={() => resetErrorBoundary()}>Try again</button>
352
+ * </div>
353
+ * )}
354
+ * >
355
+ * <Suspense fallback={<h1>Loading dashboard...</h1>}>
356
+ * <Dashboard />
357
+ * </Suspense>
358
+ * </ErrorBoundary>
359
+ * )}
360
+ * </QueryErrorResetBoundary>
361
+ * )
362
+ * }
363
+ * ```
364
+ */
54
365
  declare function useSuspenseQueries<T extends Array<any>, TCombinedResult = SuspenseQueriesResults<T>>(options: {
366
+ /**
367
+ * An array with query option objects identical to `useSuspenseQuery`.
368
+ */
55
369
  queries: readonly [...SuspenseQueriesOptions<T>];
370
+ /**
371
+ * Use this to combine the results of the queries into a single value. The result will be structurally
372
+ * shared to be as referentially stable as possible.
373
+ */
56
374
  combine?: (result: SuspenseQueriesResults<T>) => TCombinedResult;
57
375
  }, queryClient?: QueryClient): TCombinedResult;
58
376
  //#endregion