@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
@@ -1,6 +1,73 @@
1
1
  import { UseSuspenseQueryOptions, UseSuspenseQueryResult } from "./types.js";
2
2
  import { DefaultError, QueryClient, QueryKey } from "@tanstack/query-core";
3
3
  //#region src/useSuspenseQuery.d.ts
4
+ /**
5
+ * The options for `useSuspenseQuery` are the same as for `useQuery`, except for `throwOnError`, `enabled`, and
6
+ * `placeholderData` — and `queryFn` may not be `skipToken`, since Suspense hooks can't render a "disabled" state.
7
+ *
8
+ * Caveat: cancellation does not work.
9
+ *
10
+ * @remarks Multiple `useSuspenseQuery` 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 then.
12
+ * Use {@link useSuspenseQueries} instead when you have more than one suspenseful query in a component, so they
13
+ * fetch in parallel.
14
+ * @param options - The {@link UseSuspenseQueryOptions} to use — the same options as `useQuery`, minus the ones listed above.
15
+ * @param queryClient - Use this to use a custom `QueryClient`. Otherwise, the one from the nearest context will
16
+ * be used.
17
+ * @returns The same object as `useQuery`, except that `data` is guaranteed to be defined, `isPlaceholderData`
18
+ * is missing, and `status` is either `success` or `error` (with the derived flags set accordingly).
19
+ *
20
+ * @example
21
+ * The query error is thrown if the fetch fails and no cached data exists yet, so an error boundary is
22
+ * required around `<Suspense>`. A failed background refetch instead continues to render the cached data.
23
+ * Use {@link QueryErrorResetBoundary} to let the user retry after such an error:
24
+ * ```tsx
25
+ * import { Suspense } from 'react'
26
+ * import { ErrorBoundary } from 'react-error-boundary'
27
+ * import { QueryErrorResetBoundary, useSuspenseQuery } from '@tanstack/react-query'
28
+ *
29
+ * function Posts() {
30
+ * // `data` is guaranteed to be defined here — no `isPending` check needed.
31
+ * const { data, isFetching } = useSuspenseQuery({
32
+ * queryKey: ['posts'],
33
+ * queryFn: fetchPosts,
34
+ * })
35
+ *
36
+ * return (
37
+ * <div>
38
+ * <h1>Posts {isFetching ? '(refreshing...)' : null}</h1>
39
+ * <ul>
40
+ * {data.map((post) => (
41
+ * <li key={post.id}>{post.title}</li>
42
+ * ))}
43
+ * </ul>
44
+ * </div>
45
+ * )
46
+ * }
47
+ *
48
+ * function App() {
49
+ * return (
50
+ * <QueryErrorResetBoundary>
51
+ * {({ reset }) => (
52
+ * <ErrorBoundary
53
+ * onReset={reset}
54
+ * fallbackRender={({ resetErrorBoundary }) => (
55
+ * <div>
56
+ * There was an error!
57
+ * <button onClick={() => resetErrorBoundary()}>Try again</button>
58
+ * </div>
59
+ * )}
60
+ * >
61
+ * <Suspense fallback={<h1>Loading posts...</h1>}>
62
+ * <Posts />
63
+ * </Suspense>
64
+ * </ErrorBoundary>
65
+ * )}
66
+ * </QueryErrorResetBoundary>
67
+ * )
68
+ * }
69
+ * ```
70
+ */
4
71
  declare function useSuspenseQuery<TQueryFnData = unknown, TError = DefaultError, TData = TQueryFnData, TQueryKey extends QueryKey = QueryKey>(options: UseSuspenseQueryOptions<TQueryFnData, TError, TData, TQueryKey>, queryClient?: QueryClient): UseSuspenseQueryResult<TData, TError>;
5
72
  //#endregion
6
73
  export { useSuspenseQuery };
@@ -1 +1 @@
1
- {"version":3,"file":"useSuspenseQuery.d.ts","names":[],"sources":["../../src/useSuspenseQuery.ts"],"mappings":";;;iBAOgB,iBACd,wBACA,SAAS,cACT,QAAQ,cACR,kBAAkB,WAAW,UAE7B,SAAS,wBAAwB,cAAc,QAAQ,OAAO,YAC9D,cAAc,cACb,uBAAuB,OAAO"}
1
+ {"version":3,"file":"useSuspenseQuery.d.ts","names":[],"sources":["../../src/useSuspenseQuery.ts"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;iBA0EgB,iBACd,wBACA,SAAS,cACT,QAAQ,cACR,kBAAkB,WAAW,UAE7B,SAAS,wBAAwB,cAAc,QAAQ,OAAO,YAC9D,cAAc,cACb,uBAAuB,OAAO"}
@@ -3,6 +3,73 @@ import { defaultThrowOnError } from "./suspense.js";
3
3
  import { useBaseQuery } from "./useBaseQuery.js";
4
4
  import { QueryObserver, skipToken } from "@tanstack/query-core";
5
5
  //#region src/useSuspenseQuery.ts
6
+ /**
7
+ * The options for `useSuspenseQuery` are the same as for `useQuery`, except for `throwOnError`, `enabled`, and
8
+ * `placeholderData` — and `queryFn` may not be `skipToken`, since Suspense hooks can't render a "disabled" state.
9
+ *
10
+ * Caveat: cancellation does not work.
11
+ *
12
+ * @remarks Multiple `useSuspenseQuery` calls in the same component suspend serially, causing a request
13
+ * waterfall — each one blocks rendering until it resolves, so the next doesn't even start fetching until then.
14
+ * Use {@link useSuspenseQueries} instead when you have more than one suspenseful query in a component, so they
15
+ * fetch in parallel.
16
+ * @param options - The {@link UseSuspenseQueryOptions} to use — the same options as `useQuery`, minus the ones listed above.
17
+ * @param queryClient - Use this to use a custom `QueryClient`. Otherwise, the one from the nearest context will
18
+ * be used.
19
+ * @returns The same object as `useQuery`, except that `data` is guaranteed to be defined, `isPlaceholderData`
20
+ * is missing, and `status` is either `success` or `error` (with the derived flags set accordingly).
21
+ *
22
+ * @example
23
+ * The query error is thrown if the fetch fails and no cached data exists yet, so an error boundary is
24
+ * required around `<Suspense>`. A failed background refetch instead continues to render the cached data.
25
+ * Use {@link QueryErrorResetBoundary} to let the user retry after such an error:
26
+ * ```tsx
27
+ * import { Suspense } from 'react'
28
+ * import { ErrorBoundary } from 'react-error-boundary'
29
+ * import { QueryErrorResetBoundary, useSuspenseQuery } from '@tanstack/react-query'
30
+ *
31
+ * function Posts() {
32
+ * // `data` is guaranteed to be defined here — no `isPending` check needed.
33
+ * const { data, isFetching } = useSuspenseQuery({
34
+ * queryKey: ['posts'],
35
+ * queryFn: fetchPosts,
36
+ * })
37
+ *
38
+ * return (
39
+ * <div>
40
+ * <h1>Posts {isFetching ? '(refreshing...)' : null}</h1>
41
+ * <ul>
42
+ * {data.map((post) => (
43
+ * <li key={post.id}>{post.title}</li>
44
+ * ))}
45
+ * </ul>
46
+ * </div>
47
+ * )
48
+ * }
49
+ *
50
+ * function App() {
51
+ * return (
52
+ * <QueryErrorResetBoundary>
53
+ * {({ reset }) => (
54
+ * <ErrorBoundary
55
+ * onReset={reset}
56
+ * fallbackRender={({ resetErrorBoundary }) => (
57
+ * <div>
58
+ * There was an error!
59
+ * <button onClick={() => resetErrorBoundary()}>Try again</button>
60
+ * </div>
61
+ * )}
62
+ * >
63
+ * <Suspense fallback={<h1>Loading posts...</h1>}>
64
+ * <Posts />
65
+ * </Suspense>
66
+ * </ErrorBoundary>
67
+ * )}
68
+ * </QueryErrorResetBoundary>
69
+ * )
70
+ * }
71
+ * ```
72
+ */
6
73
  function useSuspenseQuery(options, queryClient) {
7
74
  if (process.env.NODE_ENV !== "production") {
8
75
  if (options.queryFn === skipToken) console.error("skipToken is not allowed for useSuspenseQuery");
@@ -1 +1 @@
1
- {"version":3,"file":"useSuspenseQuery.js","names":[],"sources":["../../src/useSuspenseQuery.ts"],"sourcesContent":["'use client'\nimport { QueryObserver, skipToken } from '@tanstack/query-core'\nimport { useBaseQuery } from './useBaseQuery'\nimport { defaultThrowOnError } from './suspense'\nimport type { UseSuspenseQueryOptions, UseSuspenseQueryResult } from './types'\nimport type { DefaultError, QueryClient, QueryKey } from '@tanstack/query-core'\n\nexport function useSuspenseQuery<\n TQueryFnData = unknown,\n TError = DefaultError,\n TData = TQueryFnData,\n TQueryKey extends QueryKey = QueryKey,\n>(\n options: UseSuspenseQueryOptions<TQueryFnData, TError, TData, TQueryKey>,\n queryClient?: QueryClient,\n): UseSuspenseQueryResult<TData, TError> {\n if (process.env.NODE_ENV !== 'production') {\n if ((options.queryFn as any) === skipToken) {\n console.error('skipToken is not allowed for useSuspenseQuery')\n }\n }\n\n return useBaseQuery(\n {\n ...options,\n enabled: true,\n suspense: true,\n throwOnError: defaultThrowOnError,\n placeholderData: undefined,\n },\n QueryObserver,\n queryClient,\n ) as UseSuspenseQueryResult<TData, TError>\n}\n"],"mappings":";;;;;AAOA,SAAgB,iBAMd,SACA,aACuC;CACvC,IAAI,QAAQ,IAAI,aAAa,cACtB;MAAA,QAAQ,YAAoB,WAC/B,QAAQ,MAAM,+CAA+C;CAAA;CAIjE,OAAO,aACL;EACE,GAAG;EACH,SAAS;EACT,UAAU;EACV,cAAc;EACd,iBAAiB,KAAA;CACnB,GACA,eACA,WACF;AACF"}
1
+ {"version":3,"file":"useSuspenseQuery.js","names":[],"sources":["../../src/useSuspenseQuery.ts"],"sourcesContent":["'use client'\nimport { QueryObserver, skipToken } from '@tanstack/query-core'\nimport { useBaseQuery } from './useBaseQuery'\nimport { defaultThrowOnError } from './suspense'\nimport type { UseSuspenseQueryOptions, UseSuspenseQueryResult } from './types'\nimport type { DefaultError, QueryClient, QueryKey } from '@tanstack/query-core'\n\n/**\n * The options for `useSuspenseQuery` are the same as for `useQuery`, except for `throwOnError`, `enabled`, and\n * `placeholderData` — and `queryFn` may not be `skipToken`, since Suspense hooks can't render a \"disabled\" state.\n *\n * Caveat: cancellation does not work.\n *\n * @remarks Multiple `useSuspenseQuery` 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 then.\n * Use {@link useSuspenseQueries} instead when you have more than one suspenseful query in a component, so they\n * fetch in parallel.\n * @param options - The {@link UseSuspenseQueryOptions} to use — the same options as `useQuery`, 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 `useQuery`, except that `data` is guaranteed to be defined, `isPlaceholderData`\n * is missing, and `status` is either `success` or `error` (with the derived flags set accordingly).\n *\n * @example\n * The query error is thrown if the 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 { QueryErrorResetBoundary, useSuspenseQuery } from '@tanstack/react-query'\n *\n * function Posts() {\n * // `data` is guaranteed to be defined here — no `isPending` check needed.\n * const { data, isFetching } = useSuspenseQuery({\n * queryKey: ['posts'],\n * queryFn: fetchPosts,\n * })\n *\n * return (\n * <div>\n * <h1>Posts {isFetching ? '(refreshing...)' : null}</h1>\n * <ul>\n * {data.map((post) => (\n * <li key={post.id}>{post.title}</li>\n * ))}\n * </ul>\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 posts...</h1>}>\n * <Posts />\n * </Suspense>\n * </ErrorBoundary>\n * )}\n * </QueryErrorResetBoundary>\n * )\n * }\n * ```\n */\nexport function useSuspenseQuery<\n TQueryFnData = unknown,\n TError = DefaultError,\n TData = TQueryFnData,\n TQueryKey extends QueryKey = QueryKey,\n>(\n options: UseSuspenseQueryOptions<TQueryFnData, TError, TData, TQueryKey>,\n queryClient?: QueryClient,\n): UseSuspenseQueryResult<TData, TError> {\n if (process.env.NODE_ENV !== 'production') {\n if ((options.queryFn as any) === skipToken) {\n console.error('skipToken is not allowed for useSuspenseQuery')\n }\n }\n\n return useBaseQuery(\n {\n ...options,\n enabled: true,\n suspense: true,\n throwOnError: defaultThrowOnError,\n placeholderData: undefined,\n },\n QueryObserver,\n queryClient,\n ) as UseSuspenseQueryResult<TData, TError>\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA0EA,SAAgB,iBAMd,SACA,aACuC;CACvC,IAAI,QAAQ,IAAI,aAAa,cACtB;MAAA,QAAQ,YAAoB,WAC/B,QAAQ,MAAM,+CAA+C;CAAA;CAIjE,OAAO,aACL;EACE,GAAG;EACH,SAAS;EACT,UAAU;EACV,cAAc;EACd,iBAAiB,KAAA;CACnB,GACA,eACA,WACF;AACF"}
@@ -15,4 +15,11 @@ export default [
15
15
  'sort-imports': 'off',
16
16
  },
17
17
  },
18
+ {
19
+ files: ['src/**/__testfixtures__/**'],
20
+ rules: {
21
+ // Codemod fixtures intentionally preserve historical QueryClient syntax.
22
+ 'no-restricted-syntax': 'off',
23
+ },
24
+ },
18
25
  ]
@@ -44,6 +44,51 @@ export default [
44
44
  '@typescript-eslint/no-empty-function': 'off',
45
45
  '@typescript-eslint/no-unsafe-function-type': 'off',
46
46
  'no-case-declarations': 'off',
47
+ /**
48
+ * Disallows direct calls to deprecated imperative query methods of `QueryClient`
49
+ * for new tests and code
50
+ *
51
+ * Existing tests that directly test the methods from before the refactoring
52
+ * will be grandfathered in and allowed to continue using the deprecated methods.
53
+ * They should not be removed, but new tests should use the new methods instead.
54
+ */
55
+ 'no-restricted-syntax': [
56
+ 'error',
57
+ {
58
+ selector:
59
+ 'CallExpression[callee.type="MemberExpression"]:matches([callee.property.name="fetchQuery"], [callee.computed=true][callee.property.value="fetchQuery"])',
60
+ message: 'Use queryClient.query(options) instead.',
61
+ },
62
+ {
63
+ selector:
64
+ 'CallExpression[callee.type="MemberExpression"]:matches([callee.property.name="prefetchQuery"], [callee.computed=true][callee.property.value="prefetchQuery"])',
65
+ message:
66
+ 'Use queryClient.query(options).catch(noop) instead if errors should be swallowed.',
67
+ },
68
+ {
69
+ selector:
70
+ 'CallExpression[callee.type="MemberExpression"]:matches([callee.property.name="ensureQueryData"], [callee.computed=true][callee.property.value="ensureQueryData"])',
71
+ message:
72
+ "Use queryClient.query({ ...options, staleTime: 'static' }) instead.",
73
+ },
74
+ {
75
+ selector:
76
+ 'CallExpression[callee.type="MemberExpression"]:matches([callee.property.name="fetchInfiniteQuery"], [callee.computed=true][callee.property.value="fetchInfiniteQuery"])',
77
+ message: 'Use queryClient.infiniteQuery(options) instead.',
78
+ },
79
+ {
80
+ selector:
81
+ 'CallExpression[callee.type="MemberExpression"]:matches([callee.property.name="prefetchInfiniteQuery"], [callee.computed=true][callee.property.value="prefetchInfiniteQuery"])',
82
+ message:
83
+ 'Use queryClient.infiniteQuery(options).catch(noop) instead if errors should be swallowed.',
84
+ },
85
+ {
86
+ selector:
87
+ 'CallExpression[callee.type="MemberExpression"]:matches([callee.property.name="ensureInfiniteQueryData"], [callee.computed=true][callee.property.value="ensureInfiniteQueryData"])',
88
+ message:
89
+ "Use queryClient.infiniteQuery({ ...options, staleTime: 'static' }) instead.",
90
+ },
91
+ ],
47
92
  'prefer-const': 'off',
48
93
  },
49
94
  },
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tanstack/react-query",
3
- "version": "5.102.8",
3
+ "version": "5.103.0",
4
4
  "description": "Hooks for managing, caching and syncing asynchronous and remote data in React",
5
5
  "author": "tannerlinsley",
6
6
  "license": "MIT",
@@ -44,7 +44,7 @@
44
44
  "!build/codemods/**/__tests__"
45
45
  ],
46
46
  "dependencies": {
47
- "@tanstack/query-core": "5.102.8"
47
+ "@tanstack/query-core": "5.103.0"
48
48
  },
49
49
  "devDependencies": {
50
50
  "@testing-library/react": "^16.1.0",
@@ -57,23 +57,23 @@
57
57
  "react": "^19.2.1",
58
58
  "react-dom": "^19.2.1",
59
59
  "react-error-boundary": "^4.1.2",
60
- "@tanstack/query-persist-client-core": "5.102.8",
60
+ "@tanstack/query-persist-client-core": "5.103.0",
61
61
  "@tanstack/query-test-utils": "0.0.0"
62
62
  },
63
63
  "peerDependencies": {
64
64
  "react": "^18 || ^19"
65
65
  },
66
66
  "scripts": {
67
- "clean": "premove ./build ./coverage ./dist-ts",
68
- "compile": "tsc --build",
67
+ "clean": "premove ./build ./coverage ./dist-ts ./.cache/test-types",
68
+ "compile": "tsc --project tsconfig.json",
69
69
  "test:eslint": "eslint --concurrency=auto ./src",
70
70
  "test:types": "npm-run-all --serial test:types:*",
71
- "test:types:ts56": "node ../../node_modules/typescript56/lib/tsc.js --build tsconfig.legacy.json",
72
- "test:types:ts57": "node ../../node_modules/typescript57/lib/tsc.js --build tsconfig.legacy.json",
73
- "test:types:ts58": "node ../../node_modules/typescript58/lib/tsc.js --build tsconfig.legacy.json",
74
- "test:types:ts59": "node ../../node_modules/typescript59/lib/tsc.js --build tsconfig.legacy.json",
75
- "test:types:tscurrent": "tsc --build",
76
- "test:types:ts70": "node ../../node_modules/typescript70/lib/tsc.js --build",
71
+ "test:types:ts56": "node ../../node_modules/typescript56/lib/tsc.js --project tsconfig.legacy.json --outDir .cache/test-types/ts56 --tsBuildInfoFile .cache/test-types/ts56.tsbuildinfo",
72
+ "test:types:ts57": "node ../../node_modules/typescript57/lib/tsc.js --project tsconfig.legacy.json --outDir .cache/test-types/ts57 --tsBuildInfoFile .cache/test-types/ts57.tsbuildinfo",
73
+ "test:types:ts58": "node ../../node_modules/typescript58/lib/tsc.js --project tsconfig.legacy.json --outDir .cache/test-types/ts58 --tsBuildInfoFile .cache/test-types/ts58.tsbuildinfo",
74
+ "test:types:ts59": "node ../../node_modules/typescript59/lib/tsc.js --project tsconfig.legacy.json --outDir .cache/test-types/ts59 --tsBuildInfoFile .cache/test-types/ts59.tsbuildinfo",
75
+ "test:types:tscurrent": "tsc --project tsconfig.json --outDir .cache/test-types/tscurrent --tsBuildInfoFile .cache/test-types/tscurrent.tsbuildinfo",
76
+ "test:types:ts70": "node ../../node_modules/typescript70/lib/tsc.js --project tsconfig.json --outDir .cache/test-types/ts70 --tsBuildInfoFile .cache/test-types/ts70.tsbuildinfo",
77
77
  "test:lib": "vitest",
78
78
  "test:lib:dev": "pnpm run test:lib --watch",
79
79
  "test:build": "publint --strict && attw --pack",
@@ -10,18 +10,79 @@ import type {
10
10
  QueryClient,
11
11
  } from '@tanstack/query-core'
12
12
 
13
+ /**
14
+ * The props accepted by `HydrationBoundary`.
15
+ */
13
16
  export interface HydrationBoundaryProps {
17
+ /**
18
+ * The state to hydrate.
19
+ */
14
20
  state: DehydratedState | null | undefined
21
+ /**
22
+ * Optional. Note: unlike `hydrate`, `mutations` cannot be set here.
23
+ */
15
24
  options?: OmitKeyof<HydrateOptions, 'defaultOptions'> & {
16
25
  defaultOptions?: OmitKeyof<
17
26
  Exclude<HydrateOptions['defaultOptions'], undefined>,
18
27
  'mutations'
19
28
  >
20
29
  }
30
+ /**
31
+ * The components to render — always rendered unconditionally, not gated on hydration. New queries are
32
+ * hydrated into the cache during render; for queries that already exist in the cache, only newer dehydrated
33
+ * data is hydrated, and that happens in an effect after commit, so `children` may render briefly before it
34
+ * lands.
35
+ */
21
36
  children?: React.ReactNode
37
+ /**
38
+ * Use this to use a custom `QueryClient`. Otherwise, the one from the nearest context will be used.
39
+ */
22
40
  queryClient?: QueryClient
23
41
  }
24
42
 
43
+ /**
44
+ * `HydrationBoundary` adds a previously dehydrated state into the `queryClient` that would be returned by
45
+ * `useQueryClient()`. If the client already contains data, the new queries will be intelligently merged based on
46
+ * update timestamp.
47
+ *
48
+ * Note: Only `queries` can be dehydrated with an `HydrationBoundary`.
49
+ *
50
+ * @returns The provided `children`, rendered unconditionally. New queries in `state` are hydrated into the
51
+ * cache during render; for queries already in the cache, only newer dehydrated data is hydrated, in an effect
52
+ * after commit.
53
+ *
54
+ * @example
55
+ * ```tsx
56
+ * import { HydrationBoundary } from '@tanstack/react-query'
57
+ *
58
+ * function App() {
59
+ * return <HydrationBoundary state={dehydratedState}>...</HydrationBoundary>
60
+ * }
61
+ * ```
62
+ *
63
+ * @example
64
+ * Server-side prefetch handed off to the client via `dehydrate`:
65
+ * ```tsx
66
+ * import { HydrationBoundary, dehydrate, noop } from '@tanstack/react-query'
67
+ *
68
+ * async function ServerComponent() {
69
+ * const queryClient = getQueryClient()
70
+ *
71
+ * await queryClient
72
+ * .query({
73
+ * queryKey: ['posts'],
74
+ * queryFn: fetchPosts,
75
+ * })
76
+ * .catch(noop)
77
+ *
78
+ * return (
79
+ * <HydrationBoundary state={dehydrate(queryClient)}>
80
+ * <Posts />
81
+ * </HydrationBoundary>
82
+ * )
83
+ * }
84
+ * ```
85
+ */
25
86
  export const HydrationBoundary = ({
26
87
  children,
27
88
  options = {},
@@ -78,7 +139,6 @@ export const HydrationBoundary = ({
78
139
  (dehydratedQuery.promise &&
79
140
  existingQuery.state.status !== 'pending' &&
80
141
  existingQuery.state.fetchStatus !== 'fetching' &&
81
- dehydratedQuery.dehydratedAt !== undefined &&
82
142
  dehydratedQuery.dehydratedAt >
83
143
  existingQuery.state.dataUpdatedAt)
84
144
 
@@ -3,5 +3,17 @@ import * as React from 'react'
3
3
 
4
4
  const IsRestoringContext = React.createContext(false)
5
5
 
6
+ /**
7
+ * If you are using `PersistQueryClientProvider`, you can also use the `useIsRestoring` hook alongside it to
8
+ * check if a restore is currently in progress. `useQuery` and friends also check this internally to avoid
9
+ * race conditions between the restore and mounting queries.
10
+ *
11
+ * @returns `true` while a persisted client is being restored, `false` otherwise.
12
+ */
6
13
  export const useIsRestoring = () => React.useContext(IsRestoringContext)
14
+
15
+ /**
16
+ * The Provider that `PersistQueryClientProvider` uses to signal whether a persisted client is currently
17
+ * being restored, read by `useIsRestoring`.
18
+ */
7
19
  export const IsRestoringProvider = IsRestoringContext.Provider
@@ -3,10 +3,21 @@ import * as React from 'react'
3
3
 
4
4
  import type { QueryClient } from '@tanstack/query-core'
5
5
 
6
+ /**
7
+ * The context that `useQueryClient` reads from. `QueryClientProvider` is the normal way to set it.
8
+ */
6
9
  export const QueryClientContext = React.createContext<QueryClient | undefined>(
7
10
  undefined,
8
11
  )
9
12
 
13
+ /**
14
+ * The `useQueryClient` hook returns the current `QueryClient` instance.
15
+ *
16
+ * @param queryClient - Use this to use a custom `QueryClient`. Otherwise, the one from the nearest context will
17
+ * be used.
18
+ * @returns The current `QueryClient` instance.
19
+ * @throws If no `queryClient` argument is passed and no `QueryClientProvider` is found in the component tree.
20
+ */
10
21
  export const useQueryClient = (queryClient?: QueryClient) => {
11
22
  const client = React.useContext(QueryClientContext)
12
23
 
@@ -21,11 +32,41 @@ export const useQueryClient = (queryClient?: QueryClient) => {
21
32
  return client
22
33
  }
23
34
 
35
+ /**
36
+ * The props accepted by `QueryClientProvider`.
37
+ */
24
38
  export type QueryClientProviderProps = {
39
+ /**
40
+ * **Required**
41
+ *
42
+ * The `QueryClient` instance to provide.
43
+ */
25
44
  client: QueryClient
45
+ /**
46
+ * The components that get access to the provided `QueryClient`.
47
+ */
26
48
  children?: React.ReactNode
27
49
  }
28
50
 
51
+ /**
52
+ * Use the `QueryClientProvider` component to connect and provide a `QueryClient` to your application. Also
53
+ * calls `client.mount()`/`client.unmount()` as this component mounts/unmounts, which subscribes the client to
54
+ * focus/online events (resuming any paused mutations and refetching as needed when the app regains focus or
55
+ * comes back online).
56
+ *
57
+ * @returns The provided `children`, wrapped so they can read the `QueryClient` via `useQueryClient`.
58
+ *
59
+ * @example
60
+ * ```tsx
61
+ * import { QueryClient, QueryClientProvider } from '@tanstack/react-query'
62
+ *
63
+ * const queryClient = new QueryClient()
64
+ *
65
+ * function App() {
66
+ * return <QueryClientProvider client={queryClient}>...</QueryClientProvider>
67
+ * }
68
+ * ```
69
+ */
29
70
  export const QueryClientProvider = ({
30
71
  client,
31
72
  children,
@@ -12,15 +12,27 @@ export interface QueryErrorResetBoundaryValue {
12
12
  reset: QueryErrorResetFunction
13
13
  }
14
14
 
15
+ /**
16
+ * Resets any query errors within the boundary, so queries know they can try again.
17
+ */
15
18
  function createValue(): QueryErrorResetBoundaryValue {
16
19
  let isReset = false
17
20
  return {
21
+ /**
22
+ * Clears the reset state, so queries know not to try again until the boundary is reset again.
23
+ */
18
24
  clearReset: () => {
19
25
  isReset = false
20
26
  },
27
+ /**
28
+ * Resets any query errors within the boundary, so queries know they can try again.
29
+ */
21
30
  reset: () => {
22
31
  isReset = true
23
32
  },
33
+ /**
34
+ * Returns whether the boundary has been reset and not yet cleared.
35
+ */
24
36
  isReset: () => {
25
37
  return isReset
26
38
  },
@@ -31,19 +43,96 @@ const QueryErrorResetBoundaryContext = React.createContext(createValue())
31
43
 
32
44
  // HOOK
33
45
 
46
+ /**
47
+ * This hook will reset any query errors within the closest `QueryErrorResetBoundary`. If there is no boundary
48
+ * defined it will reset them globally.
49
+ *
50
+ * @returns The boundary's {@link QueryErrorResetBoundaryValue}.
51
+ *
52
+ * @example
53
+ * ```tsx
54
+ * import { ErrorBoundary } from 'react-error-boundary'
55
+ * import { useQueryErrorResetBoundary } from '@tanstack/react-query'
56
+ *
57
+ * function App({ children }: { children: React.ReactNode }) {
58
+ * const { reset } = useQueryErrorResetBoundary()
59
+ *
60
+ * return (
61
+ * <ErrorBoundary
62
+ * onReset={reset}
63
+ * fallbackRender={({ resetErrorBoundary }) => (
64
+ * <div>
65
+ * There was an error!
66
+ * <button onClick={() => resetErrorBoundary()}>Try again</button>
67
+ * </div>
68
+ * )}
69
+ * >
70
+ * {children}
71
+ * </ErrorBoundary>
72
+ * )
73
+ * }
74
+ * ```
75
+ */
34
76
  export const useQueryErrorResetBoundary = () =>
35
77
  React.useContext(QueryErrorResetBoundaryContext)
36
78
 
37
79
  // COMPONENT
38
80
 
81
+ /**
82
+ * A render-prop function usable as `children` on `QueryErrorResetBoundary`.
83
+ *
84
+ * @param value - The boundary's {@link QueryErrorResetBoundaryValue}.
85
+ * @returns The children to render.
86
+ */
39
87
  export type QueryErrorResetBoundaryFunction = (
40
88
  value: QueryErrorResetBoundaryValue,
41
89
  ) => React.ReactNode
42
90
 
91
+ /**
92
+ * The props accepted by `QueryErrorResetBoundary`.
93
+ */
43
94
  export interface QueryErrorResetBoundaryProps {
95
+ /**
96
+ * Either a plain node, or a function that receives the boundary's {@link QueryErrorResetBoundaryValue} and
97
+ * returns a node.
98
+ */
44
99
  children: QueryErrorResetBoundaryFunction | React.ReactNode
45
100
  }
46
101
 
102
+ /**
103
+ * When using `suspense` or `throwOnError` in your queries, you need a way to let queries know that you want to
104
+ * try again when re-rendering after some error occurred. With the `QueryErrorResetBoundary` component you can
105
+ * reset any query errors within the boundaries of the component.
106
+ *
107
+ * @returns The `children`, rendered as-is, or called with the boundary's {@link QueryErrorResetBoundaryValue}
108
+ * if `children` is a function.
109
+ *
110
+ * @example
111
+ * ```tsx
112
+ * import { ErrorBoundary } from 'react-error-boundary'
113
+ * import { QueryErrorResetBoundary } from '@tanstack/react-query'
114
+ *
115
+ * function App() {
116
+ * return (
117
+ * <QueryErrorResetBoundary>
118
+ * {({ reset }) => (
119
+ * <ErrorBoundary
120
+ * onReset={reset}
121
+ * fallbackRender={({ resetErrorBoundary }) => (
122
+ * <div>
123
+ * There was an error!
124
+ * <button onClick={() => resetErrorBoundary()}>Try again</button>
125
+ * </div>
126
+ * )}
127
+ * >
128
+ * <Page />
129
+ * </ErrorBoundary>
130
+ * )}
131
+ * </QueryErrorResetBoundary>
132
+ * )
133
+ * }
134
+ * ```
135
+ */
47
136
  export const QueryErrorResetBoundary = ({
48
137
  children,
49
138
  }: QueryErrorResetBoundaryProps) => {