@tanstack/preact-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 (205) hide show
  1. package/build/legacy/HydrationBoundary.cjs +1 -1
  2. package/build/legacy/HydrationBoundary.cjs.map +1 -1
  3. package/build/legacy/HydrationBoundary.js +1 -1
  4. package/build/legacy/HydrationBoundary.js.map +1 -1
  5. package/build/legacy/QueryErrorResetBoundary.cjs +12 -12
  6. package/build/legacy/QueryErrorResetBoundary.cjs.map +1 -1
  7. package/build/legacy/QueryErrorResetBoundary.d.cts +12 -12
  8. package/build/legacy/QueryErrorResetBoundary.d.ts +12 -12
  9. package/build/legacy/QueryErrorResetBoundary.js +12 -12
  10. package/build/legacy/QueryErrorResetBoundary.js.map +1 -1
  11. package/build/legacy/infiniteQueryOptions.cjs.map +1 -1
  12. package/build/legacy/infiniteQueryOptions.d.cts +41 -55
  13. package/build/legacy/infiniteQueryOptions.d.cts.map +1 -1
  14. package/build/legacy/infiniteQueryOptions.d.ts +41 -55
  15. package/build/legacy/infiniteQueryOptions.d.ts.map +1 -1
  16. package/build/legacy/infiniteQueryOptions.js.map +1 -1
  17. package/build/legacy/mutationOptions.cjs.map +1 -1
  18. package/build/legacy/mutationOptions.d.cts +4 -17
  19. package/build/legacy/mutationOptions.d.cts.map +1 -1
  20. package/build/legacy/mutationOptions.d.ts +4 -17
  21. package/build/legacy/mutationOptions.d.ts.map +1 -1
  22. package/build/legacy/mutationOptions.js.map +1 -1
  23. package/build/legacy/queryOptions.cjs.map +1 -1
  24. package/build/legacy/queryOptions.d.cts +51 -74
  25. package/build/legacy/queryOptions.d.cts.map +1 -1
  26. package/build/legacy/queryOptions.d.ts +51 -74
  27. package/build/legacy/queryOptions.d.ts.map +1 -1
  28. package/build/legacy/queryOptions.js.map +1 -1
  29. package/build/legacy/useInfiniteQuery.cjs.map +1 -1
  30. package/build/legacy/useInfiniteQuery.d.cts +208 -36
  31. package/build/legacy/useInfiniteQuery.d.cts.map +1 -1
  32. package/build/legacy/useInfiniteQuery.d.ts +208 -36
  33. package/build/legacy/useInfiniteQuery.d.ts.map +1 -1
  34. package/build/legacy/useInfiniteQuery.js.map +1 -1
  35. package/build/legacy/useIsFetching.cjs +8 -6
  36. package/build/legacy/useIsFetching.cjs.map +1 -1
  37. package/build/legacy/useIsFetching.d.cts +8 -6
  38. package/build/legacy/useIsFetching.d.cts.map +1 -1
  39. package/build/legacy/useIsFetching.d.ts +8 -6
  40. package/build/legacy/useIsFetching.d.ts.map +1 -1
  41. package/build/legacy/useIsFetching.js +8 -6
  42. package/build/legacy/useIsFetching.js.map +1 -1
  43. package/build/legacy/useMutation.cjs +13 -11
  44. package/build/legacy/useMutation.cjs.map +1 -1
  45. package/build/legacy/useMutation.d.cts +13 -11
  46. package/build/legacy/useMutation.d.cts.map +1 -1
  47. package/build/legacy/useMutation.d.ts +13 -11
  48. package/build/legacy/useMutation.d.ts.map +1 -1
  49. package/build/legacy/useMutation.js +13 -11
  50. package/build/legacy/useMutation.js.map +1 -1
  51. package/build/legacy/useMutationState.cjs +49 -29
  52. package/build/legacy/useMutationState.cjs.map +1 -1
  53. package/build/legacy/useMutationState.d.cts +49 -29
  54. package/build/legacy/useMutationState.d.cts.map +1 -1
  55. package/build/legacy/useMutationState.d.ts +49 -29
  56. package/build/legacy/useMutationState.d.ts.map +1 -1
  57. package/build/legacy/useMutationState.js +49 -29
  58. package/build/legacy/useMutationState.js.map +1 -1
  59. package/build/legacy/useQueries.cjs +50 -23
  60. package/build/legacy/useQueries.cjs.map +1 -1
  61. package/build/legacy/useQueries.d.cts +50 -23
  62. package/build/legacy/useQueries.d.cts.map +1 -1
  63. package/build/legacy/useQueries.d.ts +50 -23
  64. package/build/legacy/useQueries.d.ts.map +1 -1
  65. package/build/legacy/useQueries.js +50 -23
  66. package/build/legacy/useQueries.js.map +1 -1
  67. package/build/legacy/useQuery.cjs.map +1 -1
  68. package/build/legacy/useQuery.d.cts +93 -33
  69. package/build/legacy/useQuery.d.cts.map +1 -1
  70. package/build/legacy/useQuery.d.ts +93 -33
  71. package/build/legacy/useQuery.d.ts.map +1 -1
  72. package/build/legacy/useQuery.js.map +1 -1
  73. package/build/legacy/useSuspenseInfiniteQuery.cjs +57 -7
  74. package/build/legacy/useSuspenseInfiniteQuery.cjs.map +1 -1
  75. package/build/legacy/useSuspenseInfiniteQuery.d.cts +57 -7
  76. package/build/legacy/useSuspenseInfiniteQuery.d.cts.map +1 -1
  77. package/build/legacy/useSuspenseInfiniteQuery.d.ts +57 -7
  78. package/build/legacy/useSuspenseInfiniteQuery.d.ts.map +1 -1
  79. package/build/legacy/useSuspenseInfiniteQuery.js +57 -7
  80. package/build/legacy/useSuspenseInfiniteQuery.js.map +1 -1
  81. package/build/legacy/useSuspenseQueries.cjs.map +1 -1
  82. package/build/legacy/useSuspenseQueries.d.cts +244 -20
  83. package/build/legacy/useSuspenseQueries.d.cts.map +1 -1
  84. package/build/legacy/useSuspenseQueries.d.ts +244 -20
  85. package/build/legacy/useSuspenseQueries.d.ts.map +1 -1
  86. package/build/legacy/useSuspenseQueries.js.map +1 -1
  87. package/build/legacy/useSuspenseQuery.cjs +48 -8
  88. package/build/legacy/useSuspenseQuery.cjs.map +1 -1
  89. package/build/legacy/useSuspenseQuery.d.cts +48 -8
  90. package/build/legacy/useSuspenseQuery.d.cts.map +1 -1
  91. package/build/legacy/useSuspenseQuery.d.ts +48 -8
  92. package/build/legacy/useSuspenseQuery.d.ts.map +1 -1
  93. package/build/legacy/useSuspenseQuery.js +48 -8
  94. package/build/legacy/useSuspenseQuery.js.map +1 -1
  95. package/build/modern/HydrationBoundary.cjs +1 -1
  96. package/build/modern/HydrationBoundary.cjs.map +1 -1
  97. package/build/modern/HydrationBoundary.js +1 -1
  98. package/build/modern/HydrationBoundary.js.map +1 -1
  99. package/build/modern/QueryErrorResetBoundary.cjs +12 -12
  100. package/build/modern/QueryErrorResetBoundary.cjs.map +1 -1
  101. package/build/modern/QueryErrorResetBoundary.d.cts +12 -12
  102. package/build/modern/QueryErrorResetBoundary.d.ts +12 -12
  103. package/build/modern/QueryErrorResetBoundary.js +12 -12
  104. package/build/modern/QueryErrorResetBoundary.js.map +1 -1
  105. package/build/modern/infiniteQueryOptions.cjs.map +1 -1
  106. package/build/modern/infiniteQueryOptions.d.cts +41 -55
  107. package/build/modern/infiniteQueryOptions.d.cts.map +1 -1
  108. package/build/modern/infiniteQueryOptions.d.ts +41 -55
  109. package/build/modern/infiniteQueryOptions.d.ts.map +1 -1
  110. package/build/modern/infiniteQueryOptions.js.map +1 -1
  111. package/build/modern/mutationOptions.cjs.map +1 -1
  112. package/build/modern/mutationOptions.d.cts +4 -17
  113. package/build/modern/mutationOptions.d.cts.map +1 -1
  114. package/build/modern/mutationOptions.d.ts +4 -17
  115. package/build/modern/mutationOptions.d.ts.map +1 -1
  116. package/build/modern/mutationOptions.js.map +1 -1
  117. package/build/modern/queryOptions.cjs.map +1 -1
  118. package/build/modern/queryOptions.d.cts +51 -74
  119. package/build/modern/queryOptions.d.cts.map +1 -1
  120. package/build/modern/queryOptions.d.ts +51 -74
  121. package/build/modern/queryOptions.d.ts.map +1 -1
  122. package/build/modern/queryOptions.js.map +1 -1
  123. package/build/modern/useInfiniteQuery.cjs.map +1 -1
  124. package/build/modern/useInfiniteQuery.d.cts +208 -36
  125. package/build/modern/useInfiniteQuery.d.cts.map +1 -1
  126. package/build/modern/useInfiniteQuery.d.ts +208 -36
  127. package/build/modern/useInfiniteQuery.d.ts.map +1 -1
  128. package/build/modern/useInfiniteQuery.js.map +1 -1
  129. package/build/modern/useIsFetching.cjs +8 -6
  130. package/build/modern/useIsFetching.cjs.map +1 -1
  131. package/build/modern/useIsFetching.d.cts +8 -6
  132. package/build/modern/useIsFetching.d.cts.map +1 -1
  133. package/build/modern/useIsFetching.d.ts +8 -6
  134. package/build/modern/useIsFetching.d.ts.map +1 -1
  135. package/build/modern/useIsFetching.js +8 -6
  136. package/build/modern/useIsFetching.js.map +1 -1
  137. package/build/modern/useMutation.cjs +13 -11
  138. package/build/modern/useMutation.cjs.map +1 -1
  139. package/build/modern/useMutation.d.cts +13 -11
  140. package/build/modern/useMutation.d.cts.map +1 -1
  141. package/build/modern/useMutation.d.ts +13 -11
  142. package/build/modern/useMutation.d.ts.map +1 -1
  143. package/build/modern/useMutation.js +13 -11
  144. package/build/modern/useMutation.js.map +1 -1
  145. package/build/modern/useMutationState.cjs +49 -29
  146. package/build/modern/useMutationState.cjs.map +1 -1
  147. package/build/modern/useMutationState.d.cts +49 -29
  148. package/build/modern/useMutationState.d.cts.map +1 -1
  149. package/build/modern/useMutationState.d.ts +49 -29
  150. package/build/modern/useMutationState.d.ts.map +1 -1
  151. package/build/modern/useMutationState.js +49 -29
  152. package/build/modern/useMutationState.js.map +1 -1
  153. package/build/modern/useQueries.cjs +50 -23
  154. package/build/modern/useQueries.cjs.map +1 -1
  155. package/build/modern/useQueries.d.cts +50 -23
  156. package/build/modern/useQueries.d.cts.map +1 -1
  157. package/build/modern/useQueries.d.ts +50 -23
  158. package/build/modern/useQueries.d.ts.map +1 -1
  159. package/build/modern/useQueries.js +50 -23
  160. package/build/modern/useQueries.js.map +1 -1
  161. package/build/modern/useQuery.cjs.map +1 -1
  162. package/build/modern/useQuery.d.cts +93 -33
  163. package/build/modern/useQuery.d.cts.map +1 -1
  164. package/build/modern/useQuery.d.ts +93 -33
  165. package/build/modern/useQuery.d.ts.map +1 -1
  166. package/build/modern/useQuery.js.map +1 -1
  167. package/build/modern/useSuspenseInfiniteQuery.cjs +57 -7
  168. package/build/modern/useSuspenseInfiniteQuery.cjs.map +1 -1
  169. package/build/modern/useSuspenseInfiniteQuery.d.cts +57 -7
  170. package/build/modern/useSuspenseInfiniteQuery.d.cts.map +1 -1
  171. package/build/modern/useSuspenseInfiniteQuery.d.ts +57 -7
  172. package/build/modern/useSuspenseInfiniteQuery.d.ts.map +1 -1
  173. package/build/modern/useSuspenseInfiniteQuery.js +57 -7
  174. package/build/modern/useSuspenseInfiniteQuery.js.map +1 -1
  175. package/build/modern/useSuspenseQueries.cjs.map +1 -1
  176. package/build/modern/useSuspenseQueries.d.cts +244 -20
  177. package/build/modern/useSuspenseQueries.d.cts.map +1 -1
  178. package/build/modern/useSuspenseQueries.d.ts +244 -20
  179. package/build/modern/useSuspenseQueries.d.ts.map +1 -1
  180. package/build/modern/useSuspenseQueries.js.map +1 -1
  181. package/build/modern/useSuspenseQuery.cjs +48 -8
  182. package/build/modern/useSuspenseQuery.cjs.map +1 -1
  183. package/build/modern/useSuspenseQuery.d.cts +48 -8
  184. package/build/modern/useSuspenseQuery.d.cts.map +1 -1
  185. package/build/modern/useSuspenseQuery.d.ts +48 -8
  186. package/build/modern/useSuspenseQuery.d.ts.map +1 -1
  187. package/build/modern/useSuspenseQuery.js +48 -8
  188. package/build/modern/useSuspenseQuery.js.map +1 -1
  189. package/build/query-codemods/eslint.config.js +7 -0
  190. package/build/query-codemods/root.eslint.config.js +45 -0
  191. package/package.json +11 -11
  192. package/src/HydrationBoundary.tsx +0 -1
  193. package/src/QueryErrorResetBoundary.tsx +12 -12
  194. package/src/infiniteQueryOptions.ts +41 -55
  195. package/src/mutationOptions.ts +4 -17
  196. package/src/queryOptions.ts +50 -73
  197. package/src/useInfiniteQuery.ts +208 -36
  198. package/src/useIsFetching.ts +8 -6
  199. package/src/useMutation.ts +13 -11
  200. package/src/useMutationState.ts +49 -29
  201. package/src/useQueries.ts +50 -23
  202. package/src/useQuery.ts +93 -33
  203. package/src/useSuspenseInfiniteQuery.ts +57 -7
  204. package/src/useSuspenseQueries.ts +244 -20
  205. package/src/useSuspenseQuery.ts +48 -8
@@ -181,8 +181,8 @@ export type SuspenseQueriesResults<
181
181
  : { [K in keyof T]: GetUseSuspenseQueryResult<T[K]> }
182
182
 
183
183
  /**
184
- * The options for `useSuspenseQueries` are the same as for `useQueries`, except that each `query` can't have
185
- * `throwOnError`, `enabled`, or `placeholderData`.
184
+ * The options for `useSuspenseQueries` are the same as for `useQueries`, except that the top-level `subscribed`
185
+ * option isn't supported, and each `query` can't have `throwOnError`, `enabled`, or `placeholderData`.
186
186
  *
187
187
  * @param options - The `queries` array to run in Suspense, and an optional `combine` function.
188
188
  * @param queryClient - Use this to provide a custom `QueryClient`. Otherwise, the one from the nearest context
@@ -196,9 +196,17 @@ export type SuspenseQueriesResults<
196
196
  * this, make sure to set a high enough `staleTime`. Cancellation does not work.
197
197
  *
198
198
  * @example
199
+ * The query error is thrown if a fetch fails and no cached data exists yet, so an error boundary is
200
+ * required around `<Suspense>`. A failed background refetch instead continues to render the cached data.
201
+ * Use {@link QueryErrorResetBoundary} to let the user retry after such an error:
199
202
  * ```tsx
200
203
  * import { Suspense } from 'preact/compat'
201
- * import { useSuspenseQueries } from '@tanstack/preact-query'
204
+ * import { useErrorBoundary } from 'preact/hooks'
205
+ * import {
206
+ * QueryErrorResetBoundary,
207
+ * useSuspenseQueries,
208
+ * } from '@tanstack/preact-query'
209
+ * import type { ComponentChildren } from 'preact'
202
210
  *
203
211
  * function Posts({ ids }: { ids: Array<number> }) {
204
212
  * // Every result is guaranteed to be defined — no per-query `isPending` check needed.
@@ -220,11 +228,44 @@ export type SuspenseQueriesResults<
220
228
  *
221
229
  * function App() {
222
230
  * return (
223
- * <Suspense fallback={<h1>Loading posts...</h1>}>
224
- * <Posts ids={[1, 2, 3]} />
225
- * </Suspense>
231
+ * <QueryErrorResetBoundary>
232
+ * {({ reset }) => (
233
+ * <ErrorBoundary
234
+ * onReset={reset}
235
+ * fallbackRender={({ resetErrorBoundary }) => (
236
+ * <div>
237
+ * There was an error!
238
+ * <button onClick={() => resetErrorBoundary()}>Try again</button>
239
+ * </div>
240
+ * )}
241
+ * >
242
+ * <Suspense fallback={<h1>Loading posts...</h1>}>
243
+ * <Posts ids={[1, 2, 3]} />
244
+ * </Suspense>
245
+ * </ErrorBoundary>
246
+ * )}
247
+ * </QueryErrorResetBoundary>
226
248
  * )
227
249
  * }
250
+ *
251
+ * function ErrorBoundary({
252
+ * children,
253
+ * onReset,
254
+ * fallbackRender,
255
+ * }: {
256
+ * children: ComponentChildren
257
+ * onReset: () => void
258
+ * fallbackRender: (props: {
259
+ * error: Error
260
+ * resetErrorBoundary: () => void
261
+ * }) => ComponentChildren
262
+ * }) {
263
+ * const [error, resetErrorBoundary] = useErrorBoundary(() => onReset())
264
+ *
265
+ * if (error) return fallbackRender({ error, resetErrorBoundary })
266
+ *
267
+ * return children
268
+ * }
228
269
  * ```
229
270
  *
230
271
  * @example
@@ -232,7 +273,12 @@ export type SuspenseQueriesResults<
232
273
  * they fetch in parallel rather than suspending one after another:
233
274
  * ```tsx
234
275
  * import { Suspense } from 'preact/compat'
235
- * import { useSuspenseQueries } from '@tanstack/preact-query'
276
+ * import { useErrorBoundary } from 'preact/hooks'
277
+ * import {
278
+ * QueryErrorResetBoundary,
279
+ * useSuspenseQueries,
280
+ * } from '@tanstack/preact-query'
281
+ * import type { ComponentChildren } from 'preact'
236
282
  *
237
283
  * function Dashboard() {
238
284
  * const [usersQuery, teamsQuery, projectsQuery] = useSuspenseQueries({
@@ -254,11 +300,110 @@ export type SuspenseQueriesResults<
254
300
  *
255
301
  * function App() {
256
302
  * return (
257
- * <Suspense fallback={<h1>Loading dashboard...</h1>}>
258
- * <Dashboard />
259
- * </Suspense>
303
+ * <QueryErrorResetBoundary>
304
+ * {({ reset }) => (
305
+ * <ErrorBoundary
306
+ * onReset={reset}
307
+ * fallbackRender={({ resetErrorBoundary }) => (
308
+ * <div>
309
+ * There was an error!
310
+ * <button onClick={() => resetErrorBoundary()}>Try again</button>
311
+ * </div>
312
+ * )}
313
+ * >
314
+ * <Suspense fallback={<h1>Loading dashboard...</h1>}>
315
+ * <Dashboard />
316
+ * </Suspense>
317
+ * </ErrorBoundary>
318
+ * )}
319
+ * </QueryErrorResetBoundary>
320
+ * )
321
+ * }
322
+ *
323
+ * function ErrorBoundary({
324
+ * children,
325
+ * onReset,
326
+ * fallbackRender,
327
+ * }: {
328
+ * children: ComponentChildren
329
+ * onReset: () => void
330
+ * fallbackRender: (props: {
331
+ * error: Error
332
+ * resetErrorBoundary: () => void
333
+ * }) => ComponentChildren
334
+ * }) {
335
+ * const [error, resetErrorBoundary] = useErrorBoundary(() => onReset())
336
+ *
337
+ * if (error) return fallbackRender({ error, resetErrorBoundary })
338
+ *
339
+ * return children
340
+ * }
341
+ * ```
342
+ *
343
+ * @example
344
+ * `combine`s the results into a single boolean, so `Refresh` only re-renders when that boolean changes,
345
+ * not on every individual query update. This overload is the only one that accepts `combine`:
346
+ * ```tsx
347
+ * import { Suspense } from 'preact/compat'
348
+ * import { useErrorBoundary } from 'preact/hooks'
349
+ * import {
350
+ * QueryErrorResetBoundary,
351
+ * useSuspenseQueries,
352
+ * } from '@tanstack/preact-query'
353
+ * import type { ComponentChildren } from 'preact'
354
+ *
355
+ * function Refresh() {
356
+ * const anyFetching = useSuspenseQueries({
357
+ * queries: [
358
+ * { queryKey: ['users'], queryFn: fetchUsers },
359
+ * { queryKey: ['teams'], queryFn: fetchTeams },
360
+ * ],
361
+ * combine: (results) => results.some((result) => result.isFetching),
362
+ * })
363
+ *
364
+ * return anyFetching ? <span>Refreshing…</span> : null
365
+ * }
366
+ *
367
+ * function App() {
368
+ * return (
369
+ * <QueryErrorResetBoundary>
370
+ * {({ reset }) => (
371
+ * <ErrorBoundary
372
+ * onReset={reset}
373
+ * fallbackRender={({ resetErrorBoundary }) => (
374
+ * <div>
375
+ * There was an error!
376
+ * <button onClick={() => resetErrorBoundary()}>Try again</button>
377
+ * </div>
378
+ * )}
379
+ * >
380
+ * <Suspense fallback={<h1>Loading dashboard...</h1>}>
381
+ * <Refresh />
382
+ * </Suspense>
383
+ * </ErrorBoundary>
384
+ * )}
385
+ * </QueryErrorResetBoundary>
260
386
  * )
261
387
  * }
388
+ *
389
+ * function ErrorBoundary({
390
+ * children,
391
+ * onReset,
392
+ * fallbackRender,
393
+ * }: {
394
+ * children: ComponentChildren
395
+ * onReset: () => void
396
+ * fallbackRender: (props: {
397
+ * error: Error
398
+ * resetErrorBoundary: () => void
399
+ * }) => ComponentChildren
400
+ * }) {
401
+ * const [error, resetErrorBoundary] = useErrorBoundary(() => onReset())
402
+ *
403
+ * if (error) return fallbackRender({ error, resetErrorBoundary })
404
+ *
405
+ * return children
406
+ * }
262
407
  * ```
263
408
  */
264
409
  export function useSuspenseQueries<
@@ -282,8 +427,8 @@ export function useSuspenseQueries<
282
427
  ): TCombinedResult
283
428
 
284
429
  /**
285
- * The options for `useSuspenseQueries` are the same as for `useQueries`, except that each `query` can't have
286
- * `throwOnError`, `enabled`, or `placeholderData`.
430
+ * The options for `useSuspenseQueries` are the same as for `useQueries`, except that the top-level `subscribed`
431
+ * option isn't supported, and each `query` can't have `throwOnError`, `enabled`, or `placeholderData`.
287
432
  *
288
433
  * @param options - The `queries` array to run in Suspense, and an optional `combine` function.
289
434
  * @param queryClient - Use this to provide a custom `QueryClient`. Otherwise, the one from the nearest context
@@ -297,9 +442,17 @@ export function useSuspenseQueries<
297
442
  * this, make sure to set a high enough `staleTime`. Cancellation does not work.
298
443
  *
299
444
  * @example
445
+ * The query error is thrown if a fetch fails and no cached data exists yet, so an error boundary is
446
+ * required around `<Suspense>`. A failed background refetch instead continues to render the cached data.
447
+ * Use {@link QueryErrorResetBoundary} to let the user retry after such an error:
300
448
  * ```tsx
301
449
  * import { Suspense } from 'preact/compat'
302
- * import { useSuspenseQueries } from '@tanstack/preact-query'
450
+ * import { useErrorBoundary } from 'preact/hooks'
451
+ * import {
452
+ * QueryErrorResetBoundary,
453
+ * useSuspenseQueries,
454
+ * } from '@tanstack/preact-query'
455
+ * import type { ComponentChildren } from 'preact'
303
456
  *
304
457
  * function Posts({ ids }: { ids: Array<number> }) {
305
458
  * // Every result is guaranteed to be defined — no per-query `isPending` check needed.
@@ -321,11 +474,44 @@ export function useSuspenseQueries<
321
474
  *
322
475
  * function App() {
323
476
  * return (
324
- * <Suspense fallback={<h1>Loading posts...</h1>}>
325
- * <Posts ids={[1, 2, 3]} />
326
- * </Suspense>
477
+ * <QueryErrorResetBoundary>
478
+ * {({ reset }) => (
479
+ * <ErrorBoundary
480
+ * onReset={reset}
481
+ * fallbackRender={({ resetErrorBoundary }) => (
482
+ * <div>
483
+ * There was an error!
484
+ * <button onClick={() => resetErrorBoundary()}>Try again</button>
485
+ * </div>
486
+ * )}
487
+ * >
488
+ * <Suspense fallback={<h1>Loading posts...</h1>}>
489
+ * <Posts ids={[1, 2, 3]} />
490
+ * </Suspense>
491
+ * </ErrorBoundary>
492
+ * )}
493
+ * </QueryErrorResetBoundary>
327
494
  * )
328
495
  * }
496
+ *
497
+ * function ErrorBoundary({
498
+ * children,
499
+ * onReset,
500
+ * fallbackRender,
501
+ * }: {
502
+ * children: ComponentChildren
503
+ * onReset: () => void
504
+ * fallbackRender: (props: {
505
+ * error: Error
506
+ * resetErrorBoundary: () => void
507
+ * }) => ComponentChildren
508
+ * }) {
509
+ * const [error, resetErrorBoundary] = useErrorBoundary(() => onReset())
510
+ *
511
+ * if (error) return fallbackRender({ error, resetErrorBoundary })
512
+ *
513
+ * return children
514
+ * }
329
515
  * ```
330
516
  *
331
517
  * @example
@@ -333,7 +519,12 @@ export function useSuspenseQueries<
333
519
  * they fetch in parallel rather than suspending one after another:
334
520
  * ```tsx
335
521
  * import { Suspense } from 'preact/compat'
336
- * import { useSuspenseQueries } from '@tanstack/preact-query'
522
+ * import { useErrorBoundary } from 'preact/hooks'
523
+ * import {
524
+ * QueryErrorResetBoundary,
525
+ * useSuspenseQueries,
526
+ * } from '@tanstack/preact-query'
527
+ * import type { ComponentChildren } from 'preact'
337
528
  *
338
529
  * function Dashboard() {
339
530
  * const [usersQuery, teamsQuery, projectsQuery] = useSuspenseQueries({
@@ -355,11 +546,44 @@ export function useSuspenseQueries<
355
546
  *
356
547
  * function App() {
357
548
  * return (
358
- * <Suspense fallback={<h1>Loading dashboard...</h1>}>
359
- * <Dashboard />
360
- * </Suspense>
549
+ * <QueryErrorResetBoundary>
550
+ * {({ reset }) => (
551
+ * <ErrorBoundary
552
+ * onReset={reset}
553
+ * fallbackRender={({ resetErrorBoundary }) => (
554
+ * <div>
555
+ * There was an error!
556
+ * <button onClick={() => resetErrorBoundary()}>Try again</button>
557
+ * </div>
558
+ * )}
559
+ * >
560
+ * <Suspense fallback={<h1>Loading dashboard...</h1>}>
561
+ * <Dashboard />
562
+ * </Suspense>
563
+ * </ErrorBoundary>
564
+ * )}
565
+ * </QueryErrorResetBoundary>
361
566
  * )
362
567
  * }
568
+ *
569
+ * function ErrorBoundary({
570
+ * children,
571
+ * onReset,
572
+ * fallbackRender,
573
+ * }: {
574
+ * children: ComponentChildren
575
+ * onReset: () => void
576
+ * fallbackRender: (props: {
577
+ * error: Error
578
+ * resetErrorBoundary: () => void
579
+ * }) => ComponentChildren
580
+ * }) {
581
+ * const [error, resetErrorBoundary] = useErrorBoundary(() => onReset())
582
+ *
583
+ * if (error) return fallbackRender({ error, resetErrorBoundary })
584
+ *
585
+ * return children
586
+ * }
363
587
  * ```
364
588
  */
365
589
  export function useSuspenseQueries<
@@ -22,9 +22,14 @@ import { useBaseQuery } from './useBaseQuery'
22
22
  * is missing, and `status` is either `success` or `error` (with the derived flags set accordingly).
23
23
  *
24
24
  * @example
25
+ * The query error is thrown if the 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:
25
28
  * ```tsx
26
29
  * import { Suspense } from 'preact/compat'
27
- * import { useSuspenseQuery } from '@tanstack/preact-query'
30
+ * import { useErrorBoundary } from 'preact/hooks'
31
+ * import { QueryErrorResetBoundary, useSuspenseQuery } from '@tanstack/preact-query'
32
+ * import type { ComponentChildren } from 'preact'
28
33
  *
29
34
  * function Posts() {
30
35
  * // `data` is guaranteed to be defined here — no `isPending` check needed.
@@ -35,21 +40,56 @@ import { useBaseQuery } from './useBaseQuery'
35
40
  *
36
41
  * return (
37
42
  * <div>
38
- * <h1>Posts {isFetching ? <Spinner /> : null}</h1>
39
- * {data.map((post) => (
40
- * <p key={post.id}>{post.title}</p>
41
- * ))}
43
+ * <h1>Posts {isFetching ? '(refreshing...)' : null}</h1>
44
+ * <ul>
45
+ * {data.map((post) => (
46
+ * <li key={post.id}>{post.title}</li>
47
+ * ))}
48
+ * </ul>
42
49
  * </div>
43
50
  * )
44
51
  * }
45
52
  *
46
53
  * function App() {
47
54
  * return (
48
- * <Suspense fallback={<h1>Loading posts...</h1>}>
49
- * <Posts />
50
- * </Suspense>
55
+ * <QueryErrorResetBoundary>
56
+ * {({ reset }) => (
57
+ * <ErrorBoundary
58
+ * onReset={reset}
59
+ * fallbackRender={({ resetErrorBoundary }) => (
60
+ * <div>
61
+ * There was an error!
62
+ * <button onClick={() => resetErrorBoundary()}>Try again</button>
63
+ * </div>
64
+ * )}
65
+ * >
66
+ * <Suspense fallback={<h1>Loading posts...</h1>}>
67
+ * <Posts />
68
+ * </Suspense>
69
+ * </ErrorBoundary>
70
+ * )}
71
+ * </QueryErrorResetBoundary>
51
72
  * )
52
73
  * }
74
+ *
75
+ * function ErrorBoundary({
76
+ * children,
77
+ * onReset,
78
+ * fallbackRender,
79
+ * }: {
80
+ * children: ComponentChildren
81
+ * onReset: () => void
82
+ * fallbackRender: (props: {
83
+ * error: Error
84
+ * resetErrorBoundary: () => void
85
+ * }) => ComponentChildren
86
+ * }) {
87
+ * const [error, resetErrorBoundary] = useErrorBoundary(() => onReset())
88
+ *
89
+ * if (error) return fallbackRender({ error, resetErrorBoundary })
90
+ *
91
+ * return children
92
+ * }
53
93
  * ```
54
94
  */
55
95
  export function useSuspenseQuery<