@tanstack/react-query 5.104.1 → 5.104.2

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 (347) hide show
  1. package/build/legacy/HydrationBoundary.cjs +2 -3
  2. package/build/legacy/HydrationBoundary.cjs.map +1 -1
  3. package/build/legacy/HydrationBoundary.d.cts +2 -3
  4. package/build/legacy/HydrationBoundary.d.cts.map +1 -1
  5. package/build/legacy/HydrationBoundary.d.ts +2 -3
  6. package/build/legacy/HydrationBoundary.d.ts.map +1 -1
  7. package/build/legacy/HydrationBoundary.js +2 -3
  8. package/build/legacy/HydrationBoundary.js.map +1 -1
  9. package/build/legacy/IsRestoringProvider.cjs +0 -1
  10. package/build/legacy/IsRestoringProvider.cjs.map +1 -1
  11. package/build/legacy/IsRestoringProvider.d.cts +0 -1
  12. package/build/legacy/IsRestoringProvider.d.cts.map +1 -1
  13. package/build/legacy/IsRestoringProvider.d.ts +0 -1
  14. package/build/legacy/IsRestoringProvider.d.ts.map +1 -1
  15. package/build/legacy/IsRestoringProvider.js +0 -1
  16. package/build/legacy/IsRestoringProvider.js.map +1 -1
  17. package/build/legacy/QueryClientProvider.cjs +3 -4
  18. package/build/legacy/QueryClientProvider.cjs.map +1 -1
  19. package/build/legacy/QueryClientProvider.d.cts +3 -4
  20. package/build/legacy/QueryClientProvider.d.cts.map +1 -1
  21. package/build/legacy/QueryClientProvider.d.ts +3 -4
  22. package/build/legacy/QueryClientProvider.d.ts.map +1 -1
  23. package/build/legacy/QueryClientProvider.js +3 -4
  24. package/build/legacy/QueryClientProvider.js.map +1 -1
  25. package/build/legacy/QueryErrorResetBoundary.cjs +5 -5
  26. package/build/legacy/QueryErrorResetBoundary.cjs.map +1 -1
  27. package/build/legacy/QueryErrorResetBoundary.d.cts +23 -5
  28. package/build/legacy/QueryErrorResetBoundary.d.cts.map +1 -1
  29. package/build/legacy/QueryErrorResetBoundary.d.ts +23 -5
  30. package/build/legacy/QueryErrorResetBoundary.d.ts.map +1 -1
  31. package/build/legacy/QueryErrorResetBoundary.js +5 -5
  32. package/build/legacy/QueryErrorResetBoundary.js.map +1 -1
  33. package/build/legacy/errorBoundaryUtils.cjs +21 -0
  34. package/build/legacy/errorBoundaryUtils.cjs.map +1 -1
  35. package/build/legacy/errorBoundaryUtils.d.cts +21 -0
  36. package/build/legacy/errorBoundaryUtils.d.cts.map +1 -1
  37. package/build/legacy/errorBoundaryUtils.d.ts +21 -0
  38. package/build/legacy/errorBoundaryUtils.d.ts.map +1 -1
  39. package/build/legacy/errorBoundaryUtils.js +21 -0
  40. package/build/legacy/errorBoundaryUtils.js.map +1 -1
  41. package/build/legacy/infiniteQueryOptions.cjs.map +1 -1
  42. package/build/legacy/infiniteQueryOptions.d.cts +5 -16
  43. package/build/legacy/infiniteQueryOptions.d.cts.map +1 -1
  44. package/build/legacy/infiniteQueryOptions.d.ts +5 -16
  45. package/build/legacy/infiniteQueryOptions.d.ts.map +1 -1
  46. package/build/legacy/infiniteQueryOptions.js.map +1 -1
  47. package/build/legacy/mutationOptions.cjs.map +1 -1
  48. package/build/legacy/mutationOptions.d.cts +2 -6
  49. package/build/legacy/mutationOptions.d.cts.map +1 -1
  50. package/build/legacy/mutationOptions.d.ts +2 -6
  51. package/build/legacy/mutationOptions.d.ts.map +1 -1
  52. package/build/legacy/mutationOptions.js.map +1 -1
  53. package/build/legacy/queryOptions.cjs.map +1 -1
  54. package/build/legacy/queryOptions.d.cts +6 -16
  55. package/build/legacy/queryOptions.d.cts.map +1 -1
  56. package/build/legacy/queryOptions.d.ts +6 -16
  57. package/build/legacy/queryOptions.d.ts.map +1 -1
  58. package/build/legacy/queryOptions.js.map +1 -1
  59. package/build/legacy/suspense.cjs +27 -0
  60. package/build/legacy/suspense.cjs.map +1 -1
  61. package/build/legacy/suspense.d.cts +27 -0
  62. package/build/legacy/suspense.d.cts.map +1 -1
  63. package/build/legacy/suspense.d.ts +27 -0
  64. package/build/legacy/suspense.d.ts.map +1 -1
  65. package/build/legacy/suspense.js +27 -0
  66. package/build/legacy/suspense.js.map +1 -1
  67. package/build/legacy/types.cjs.map +1 -1
  68. package/build/legacy/types.d.cts +2 -22
  69. package/build/legacy/types.d.cts.map +1 -1
  70. package/build/legacy/types.d.ts +2 -22
  71. package/build/legacy/types.d.ts.map +1 -1
  72. package/build/legacy/types.js.map +1 -1
  73. package/build/legacy/useBaseQuery.cjs +13 -0
  74. package/build/legacy/useBaseQuery.cjs.map +1 -1
  75. package/build/legacy/useBaseQuery.d.cts +13 -0
  76. package/build/legacy/useBaseQuery.d.cts.map +1 -1
  77. package/build/legacy/useBaseQuery.d.ts +13 -0
  78. package/build/legacy/useBaseQuery.d.ts.map +1 -1
  79. package/build/legacy/useBaseQuery.js +13 -0
  80. package/build/legacy/useBaseQuery.js.map +1 -1
  81. package/build/legacy/useInfiniteQuery.cjs.map +1 -1
  82. package/build/legacy/useInfiniteQuery.d.cts +12 -21
  83. package/build/legacy/useInfiniteQuery.d.cts.map +1 -1
  84. package/build/legacy/useInfiniteQuery.d.ts +12 -21
  85. package/build/legacy/useInfiniteQuery.d.ts.map +1 -1
  86. package/build/legacy/useInfiniteQuery.js.map +1 -1
  87. package/build/legacy/useIsFetching.cjs +0 -3
  88. package/build/legacy/useIsFetching.cjs.map +1 -1
  89. package/build/legacy/useIsFetching.d.cts +0 -3
  90. package/build/legacy/useIsFetching.d.cts.map +1 -1
  91. package/build/legacy/useIsFetching.d.ts +0 -3
  92. package/build/legacy/useIsFetching.d.ts.map +1 -1
  93. package/build/legacy/useIsFetching.js +0 -3
  94. package/build/legacy/useIsFetching.js.map +1 -1
  95. package/build/legacy/useMutation.cjs +4 -8
  96. package/build/legacy/useMutation.cjs.map +1 -1
  97. package/build/legacy/useMutation.d.cts +4 -8
  98. package/build/legacy/useMutation.d.cts.map +1 -1
  99. package/build/legacy/useMutation.d.ts +4 -8
  100. package/build/legacy/useMutation.d.ts.map +1 -1
  101. package/build/legacy/useMutation.js +4 -8
  102. package/build/legacy/useMutation.js.map +1 -1
  103. package/build/legacy/useMutationState.cjs +7 -6
  104. package/build/legacy/useMutationState.cjs.map +1 -1
  105. package/build/legacy/useMutationState.d.cts +0 -6
  106. package/build/legacy/useMutationState.d.cts.map +1 -1
  107. package/build/legacy/useMutationState.d.ts +0 -6
  108. package/build/legacy/useMutationState.d.ts.map +1 -1
  109. package/build/legacy/useMutationState.js +7 -6
  110. package/build/legacy/useMutationState.js.map +1 -1
  111. package/build/legacy/usePrefetchInfiniteQuery.cjs +0 -3
  112. package/build/legacy/usePrefetchInfiniteQuery.cjs.map +1 -1
  113. package/build/legacy/usePrefetchInfiniteQuery.d.cts +0 -3
  114. package/build/legacy/usePrefetchInfiniteQuery.d.cts.map +1 -1
  115. package/build/legacy/usePrefetchInfiniteQuery.d.ts +0 -3
  116. package/build/legacy/usePrefetchInfiniteQuery.d.ts.map +1 -1
  117. package/build/legacy/usePrefetchInfiniteQuery.js +0 -3
  118. package/build/legacy/usePrefetchInfiniteQuery.js.map +1 -1
  119. package/build/legacy/usePrefetchQuery.cjs +0 -3
  120. package/build/legacy/usePrefetchQuery.cjs.map +1 -1
  121. package/build/legacy/usePrefetchQuery.d.cts +0 -3
  122. package/build/legacy/usePrefetchQuery.d.cts.map +1 -1
  123. package/build/legacy/usePrefetchQuery.d.ts +0 -3
  124. package/build/legacy/usePrefetchQuery.d.ts.map +1 -1
  125. package/build/legacy/usePrefetchQuery.js +0 -3
  126. package/build/legacy/usePrefetchQuery.js.map +1 -1
  127. package/build/legacy/useQueries.cjs +7 -8
  128. package/build/legacy/useQueries.cjs.map +1 -1
  129. package/build/legacy/useQueries.d.cts +7 -11
  130. package/build/legacy/useQueries.d.cts.map +1 -1
  131. package/build/legacy/useQueries.d.ts +7 -11
  132. package/build/legacy/useQueries.d.ts.map +1 -1
  133. package/build/legacy/useQueries.js +7 -8
  134. package/build/legacy/useQueries.js.map +1 -1
  135. package/build/legacy/useQuery.cjs.map +1 -1
  136. package/build/legacy/useQuery.d.cts +8 -13
  137. package/build/legacy/useQuery.d.cts.map +1 -1
  138. package/build/legacy/useQuery.d.ts +8 -13
  139. package/build/legacy/useQuery.d.ts.map +1 -1
  140. package/build/legacy/useQuery.js.map +1 -1
  141. package/build/legacy/useSuspenseInfiniteQuery.cjs +6 -8
  142. package/build/legacy/useSuspenseInfiniteQuery.cjs.map +1 -1
  143. package/build/legacy/useSuspenseInfiniteQuery.d.cts +6 -8
  144. package/build/legacy/useSuspenseInfiniteQuery.d.cts.map +1 -1
  145. package/build/legacy/useSuspenseInfiniteQuery.d.ts +6 -8
  146. package/build/legacy/useSuspenseInfiniteQuery.d.ts.map +1 -1
  147. package/build/legacy/useSuspenseInfiniteQuery.js +6 -8
  148. package/build/legacy/useSuspenseInfiniteQuery.js.map +1 -1
  149. package/build/legacy/useSuspenseQueries.cjs.map +1 -1
  150. package/build/legacy/useSuspenseQueries.d.cts +0 -9
  151. package/build/legacy/useSuspenseQueries.d.cts.map +1 -1
  152. package/build/legacy/useSuspenseQueries.d.ts +0 -9
  153. package/build/legacy/useSuspenseQueries.d.ts.map +1 -1
  154. package/build/legacy/useSuspenseQueries.js.map +1 -1
  155. package/build/legacy/useSuspenseQuery.cjs +4 -6
  156. package/build/legacy/useSuspenseQuery.cjs.map +1 -1
  157. package/build/legacy/useSuspenseQuery.d.cts +4 -6
  158. package/build/legacy/useSuspenseQuery.d.cts.map +1 -1
  159. package/build/legacy/useSuspenseQuery.d.ts +4 -6
  160. package/build/legacy/useSuspenseQuery.d.ts.map +1 -1
  161. package/build/legacy/useSuspenseQuery.js +4 -6
  162. package/build/legacy/useSuspenseQuery.js.map +1 -1
  163. package/build/modern/HydrationBoundary.cjs +2 -3
  164. package/build/modern/HydrationBoundary.cjs.map +1 -1
  165. package/build/modern/HydrationBoundary.d.cts +2 -3
  166. package/build/modern/HydrationBoundary.d.cts.map +1 -1
  167. package/build/modern/HydrationBoundary.d.ts +2 -3
  168. package/build/modern/HydrationBoundary.d.ts.map +1 -1
  169. package/build/modern/HydrationBoundary.js +2 -3
  170. package/build/modern/HydrationBoundary.js.map +1 -1
  171. package/build/modern/IsRestoringProvider.cjs +0 -1
  172. package/build/modern/IsRestoringProvider.cjs.map +1 -1
  173. package/build/modern/IsRestoringProvider.d.cts +0 -1
  174. package/build/modern/IsRestoringProvider.d.cts.map +1 -1
  175. package/build/modern/IsRestoringProvider.d.ts +0 -1
  176. package/build/modern/IsRestoringProvider.d.ts.map +1 -1
  177. package/build/modern/IsRestoringProvider.js +0 -1
  178. package/build/modern/IsRestoringProvider.js.map +1 -1
  179. package/build/modern/QueryClientProvider.cjs +3 -4
  180. package/build/modern/QueryClientProvider.cjs.map +1 -1
  181. package/build/modern/QueryClientProvider.d.cts +3 -4
  182. package/build/modern/QueryClientProvider.d.cts.map +1 -1
  183. package/build/modern/QueryClientProvider.d.ts +3 -4
  184. package/build/modern/QueryClientProvider.d.ts.map +1 -1
  185. package/build/modern/QueryClientProvider.js +3 -4
  186. package/build/modern/QueryClientProvider.js.map +1 -1
  187. package/build/modern/QueryErrorResetBoundary.cjs +5 -5
  188. package/build/modern/QueryErrorResetBoundary.cjs.map +1 -1
  189. package/build/modern/QueryErrorResetBoundary.d.cts +23 -5
  190. package/build/modern/QueryErrorResetBoundary.d.cts.map +1 -1
  191. package/build/modern/QueryErrorResetBoundary.d.ts +23 -5
  192. package/build/modern/QueryErrorResetBoundary.d.ts.map +1 -1
  193. package/build/modern/QueryErrorResetBoundary.js +5 -5
  194. package/build/modern/QueryErrorResetBoundary.js.map +1 -1
  195. package/build/modern/errorBoundaryUtils.cjs +21 -0
  196. package/build/modern/errorBoundaryUtils.cjs.map +1 -1
  197. package/build/modern/errorBoundaryUtils.d.cts +21 -0
  198. package/build/modern/errorBoundaryUtils.d.cts.map +1 -1
  199. package/build/modern/errorBoundaryUtils.d.ts +21 -0
  200. package/build/modern/errorBoundaryUtils.d.ts.map +1 -1
  201. package/build/modern/errorBoundaryUtils.js +21 -0
  202. package/build/modern/errorBoundaryUtils.js.map +1 -1
  203. package/build/modern/infiniteQueryOptions.cjs.map +1 -1
  204. package/build/modern/infiniteQueryOptions.d.cts +5 -16
  205. package/build/modern/infiniteQueryOptions.d.cts.map +1 -1
  206. package/build/modern/infiniteQueryOptions.d.ts +5 -16
  207. package/build/modern/infiniteQueryOptions.d.ts.map +1 -1
  208. package/build/modern/infiniteQueryOptions.js.map +1 -1
  209. package/build/modern/mutationOptions.cjs.map +1 -1
  210. package/build/modern/mutationOptions.d.cts +2 -6
  211. package/build/modern/mutationOptions.d.cts.map +1 -1
  212. package/build/modern/mutationOptions.d.ts +2 -6
  213. package/build/modern/mutationOptions.d.ts.map +1 -1
  214. package/build/modern/mutationOptions.js.map +1 -1
  215. package/build/modern/queryOptions.cjs.map +1 -1
  216. package/build/modern/queryOptions.d.cts +6 -16
  217. package/build/modern/queryOptions.d.cts.map +1 -1
  218. package/build/modern/queryOptions.d.ts +6 -16
  219. package/build/modern/queryOptions.d.ts.map +1 -1
  220. package/build/modern/queryOptions.js.map +1 -1
  221. package/build/modern/suspense.cjs +27 -0
  222. package/build/modern/suspense.cjs.map +1 -1
  223. package/build/modern/suspense.d.cts +27 -0
  224. package/build/modern/suspense.d.cts.map +1 -1
  225. package/build/modern/suspense.d.ts +27 -0
  226. package/build/modern/suspense.d.ts.map +1 -1
  227. package/build/modern/suspense.js +27 -0
  228. package/build/modern/suspense.js.map +1 -1
  229. package/build/modern/types.cjs.map +1 -1
  230. package/build/modern/types.d.cts +2 -22
  231. package/build/modern/types.d.cts.map +1 -1
  232. package/build/modern/types.d.ts +2 -22
  233. package/build/modern/types.d.ts.map +1 -1
  234. package/build/modern/types.js.map +1 -1
  235. package/build/modern/useBaseQuery.cjs +13 -0
  236. package/build/modern/useBaseQuery.cjs.map +1 -1
  237. package/build/modern/useBaseQuery.d.cts +13 -0
  238. package/build/modern/useBaseQuery.d.cts.map +1 -1
  239. package/build/modern/useBaseQuery.d.ts +13 -0
  240. package/build/modern/useBaseQuery.d.ts.map +1 -1
  241. package/build/modern/useBaseQuery.js +13 -0
  242. package/build/modern/useBaseQuery.js.map +1 -1
  243. package/build/modern/useInfiniteQuery.cjs.map +1 -1
  244. package/build/modern/useInfiniteQuery.d.cts +12 -21
  245. package/build/modern/useInfiniteQuery.d.cts.map +1 -1
  246. package/build/modern/useInfiniteQuery.d.ts +12 -21
  247. package/build/modern/useInfiniteQuery.d.ts.map +1 -1
  248. package/build/modern/useInfiniteQuery.js.map +1 -1
  249. package/build/modern/useIsFetching.cjs +0 -3
  250. package/build/modern/useIsFetching.cjs.map +1 -1
  251. package/build/modern/useIsFetching.d.cts +0 -3
  252. package/build/modern/useIsFetching.d.cts.map +1 -1
  253. package/build/modern/useIsFetching.d.ts +0 -3
  254. package/build/modern/useIsFetching.d.ts.map +1 -1
  255. package/build/modern/useIsFetching.js +0 -3
  256. package/build/modern/useIsFetching.js.map +1 -1
  257. package/build/modern/useMutation.cjs +4 -8
  258. package/build/modern/useMutation.cjs.map +1 -1
  259. package/build/modern/useMutation.d.cts +4 -8
  260. package/build/modern/useMutation.d.cts.map +1 -1
  261. package/build/modern/useMutation.d.ts +4 -8
  262. package/build/modern/useMutation.d.ts.map +1 -1
  263. package/build/modern/useMutation.js +4 -8
  264. package/build/modern/useMutation.js.map +1 -1
  265. package/build/modern/useMutationState.cjs +7 -6
  266. package/build/modern/useMutationState.cjs.map +1 -1
  267. package/build/modern/useMutationState.d.cts +0 -6
  268. package/build/modern/useMutationState.d.cts.map +1 -1
  269. package/build/modern/useMutationState.d.ts +0 -6
  270. package/build/modern/useMutationState.d.ts.map +1 -1
  271. package/build/modern/useMutationState.js +7 -6
  272. package/build/modern/useMutationState.js.map +1 -1
  273. package/build/modern/usePrefetchInfiniteQuery.cjs +0 -3
  274. package/build/modern/usePrefetchInfiniteQuery.cjs.map +1 -1
  275. package/build/modern/usePrefetchInfiniteQuery.d.cts +0 -3
  276. package/build/modern/usePrefetchInfiniteQuery.d.cts.map +1 -1
  277. package/build/modern/usePrefetchInfiniteQuery.d.ts +0 -3
  278. package/build/modern/usePrefetchInfiniteQuery.d.ts.map +1 -1
  279. package/build/modern/usePrefetchInfiniteQuery.js +0 -3
  280. package/build/modern/usePrefetchInfiniteQuery.js.map +1 -1
  281. package/build/modern/usePrefetchQuery.cjs +0 -3
  282. package/build/modern/usePrefetchQuery.cjs.map +1 -1
  283. package/build/modern/usePrefetchQuery.d.cts +0 -3
  284. package/build/modern/usePrefetchQuery.d.cts.map +1 -1
  285. package/build/modern/usePrefetchQuery.d.ts +0 -3
  286. package/build/modern/usePrefetchQuery.d.ts.map +1 -1
  287. package/build/modern/usePrefetchQuery.js +0 -3
  288. package/build/modern/usePrefetchQuery.js.map +1 -1
  289. package/build/modern/useQueries.cjs +7 -8
  290. package/build/modern/useQueries.cjs.map +1 -1
  291. package/build/modern/useQueries.d.cts +7 -11
  292. package/build/modern/useQueries.d.cts.map +1 -1
  293. package/build/modern/useQueries.d.ts +7 -11
  294. package/build/modern/useQueries.d.ts.map +1 -1
  295. package/build/modern/useQueries.js +7 -8
  296. package/build/modern/useQueries.js.map +1 -1
  297. package/build/modern/useQuery.cjs.map +1 -1
  298. package/build/modern/useQuery.d.cts +8 -13
  299. package/build/modern/useQuery.d.cts.map +1 -1
  300. package/build/modern/useQuery.d.ts +8 -13
  301. package/build/modern/useQuery.d.ts.map +1 -1
  302. package/build/modern/useQuery.js.map +1 -1
  303. package/build/modern/useSuspenseInfiniteQuery.cjs +6 -8
  304. package/build/modern/useSuspenseInfiniteQuery.cjs.map +1 -1
  305. package/build/modern/useSuspenseInfiniteQuery.d.cts +6 -8
  306. package/build/modern/useSuspenseInfiniteQuery.d.cts.map +1 -1
  307. package/build/modern/useSuspenseInfiniteQuery.d.ts +6 -8
  308. package/build/modern/useSuspenseInfiniteQuery.d.ts.map +1 -1
  309. package/build/modern/useSuspenseInfiniteQuery.js +6 -8
  310. package/build/modern/useSuspenseInfiniteQuery.js.map +1 -1
  311. package/build/modern/useSuspenseQueries.cjs.map +1 -1
  312. package/build/modern/useSuspenseQueries.d.cts +0 -9
  313. package/build/modern/useSuspenseQueries.d.cts.map +1 -1
  314. package/build/modern/useSuspenseQueries.d.ts +0 -9
  315. package/build/modern/useSuspenseQueries.d.ts.map +1 -1
  316. package/build/modern/useSuspenseQueries.js.map +1 -1
  317. package/build/modern/useSuspenseQuery.cjs +4 -6
  318. package/build/modern/useSuspenseQuery.cjs.map +1 -1
  319. package/build/modern/useSuspenseQuery.d.cts +4 -6
  320. package/build/modern/useSuspenseQuery.d.cts.map +1 -1
  321. package/build/modern/useSuspenseQuery.d.ts +4 -6
  322. package/build/modern/useSuspenseQuery.d.ts.map +1 -1
  323. package/build/modern/useSuspenseQuery.js +4 -6
  324. package/build/modern/useSuspenseQuery.js.map +1 -1
  325. package/package.json +6 -6
  326. package/src/HydrationBoundary.tsx +4 -5
  327. package/src/IsRestoringProvider.ts +0 -1
  328. package/src/QueryClientProvider.tsx +3 -4
  329. package/src/QueryErrorResetBoundary.tsx +30 -6
  330. package/src/errorBoundaryUtils.ts +21 -0
  331. package/src/infiniteQueryOptions.ts +5 -16
  332. package/src/mutationOptions.ts +2 -6
  333. package/src/queryOptions.ts +8 -17
  334. package/src/suspense.ts +29 -1
  335. package/src/types.ts +2 -22
  336. package/src/useBaseQuery.ts +13 -0
  337. package/src/useInfiniteQuery.ts +12 -21
  338. package/src/useIsFetching.ts +0 -3
  339. package/src/useMutation.ts +4 -8
  340. package/src/useMutationState.ts +7 -6
  341. package/src/usePrefetchInfiniteQuery.tsx +0 -3
  342. package/src/usePrefetchQuery.tsx +0 -3
  343. package/src/useQueries.ts +7 -11
  344. package/src/useQuery.ts +8 -13
  345. package/src/useSuspenseInfiniteQuery.ts +6 -8
  346. package/src/useSuspenseQueries.ts +0 -9
  347. package/src/useSuspenseQuery.ts +4 -6
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tanstack/react-query",
3
- "version": "5.104.1",
3
+ "version": "5.104.2",
4
4
  "description": "Hooks for managing, caching and syncing asynchronous and remote data in React",
5
5
  "author": "tannerlinsley",
6
6
  "license": "MIT",
@@ -44,11 +44,11 @@
44
44
  "!build/codemods/**/__tests__"
45
45
  ],
46
46
  "dependencies": {
47
- "@tanstack/query-core": "5.104.1"
47
+ "@tanstack/query-core": "5.104.2"
48
48
  },
49
49
  "devDependencies": {
50
- "@eslint-react/eslint-plugin": "^5.21.0",
51
- "@tanstack/query-persist-client-core": "5.104.1",
50
+ "@eslint-react/eslint-plugin": "^5.23.3",
51
+ "@tanstack/query-persist-client-core": "5.104.2",
52
52
  "@tanstack/query-test-utils": "0.0.0",
53
53
  "@testing-library/react": "^16.1.0",
54
54
  "@testing-library/react-render-stream": "^2.0.2",
@@ -67,14 +67,14 @@
67
67
  "scripts": {
68
68
  "clean": "premove ./build ./coverage ./dist-ts ./.cache/test-types",
69
69
  "compile": "tsc --project tsconfig.json",
70
- "test:eslint": "eslint --concurrency=auto ./src",
70
+ "test:oxlint": "oxlint ./src",
71
71
  "test:types": "npm-run-all --serial test:types:*",
72
- "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",
73
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",
74
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",
75
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",
76
75
  "test:types:tscurrent": "tsc --project tsconfig.json --outDir .cache/test-types/tscurrent --tsBuildInfoFile .cache/test-types/tscurrent.tsbuildinfo",
77
76
  "test:types:ts70": "node ../../node_modules/typescript70/lib/tsc.js --project tsconfig.legacy.json --outDir .cache/test-types/ts70 --tsBuildInfoFile .cache/test-types/ts70.tsbuildinfo",
77
+ "test:types:ts71": "node ../../node_modules/typescript71/lib/tsc.js --project tsconfig.legacy.json --outDir .cache/test-types/ts71 --tsBuildInfoFile .cache/test-types/ts71.tsbuildinfo",
78
78
  "test:lib": "vitest",
79
79
  "test:lib:dev": "pnpm run test:lib --watch",
80
80
  "test:build": "publint --strict && attw --pack",
@@ -46,11 +46,11 @@ export interface HydrationBoundaryProps {
46
46
  * update timestamp.
47
47
  *
48
48
  * Note: Only `queries` can be dehydrated with an `HydrationBoundary`.
49
- *
49
+ * @param props - The dehydrated `state` to hydrate, the hydrate `options`, an optional custom
50
+ * `queryClient`, and the `children` to render.
50
51
  * @returns The provided `children`, rendered unconditionally. New queries in `state` are hydrated into the
51
52
  * cache during render; for queries already in the cache, only newer dehydrated data is hydrated, in an effect
52
53
  * after commit.
53
- *
54
54
  * @example
55
55
  * ```tsx
56
56
  * import { HydrationBoundary } from '@tanstack/react-query'
@@ -59,7 +59,6 @@ export interface HydrationBoundaryProps {
59
59
  * return <HydrationBoundary state={dehydratedState}>...</HydrationBoundary>
60
60
  * }
61
61
  * ```
62
- *
63
62
  * @example
64
63
  * Server-side prefetch handed off to the client via `dehydrate`:
65
64
  * ```tsx
@@ -122,7 +121,7 @@ export const HydrationBoundary = ({
122
121
  // State is supplied from the outside and we might as well fail
123
122
  // gracefully if it has the wrong shape, so while we type `queries`
124
123
  // as required, we still provide a fallback.
125
- // eslint-disable-next-line @typescript-eslint/no-unnecessary-condition
124
+ // oxlint-disable-next-line typescript/no-unnecessary-condition
126
125
  const queries = state.queries || []
127
126
 
128
127
  const newQueries: DehydratedState['queries'] = []
@@ -151,7 +150,7 @@ export const HydrationBoundary = ({
151
150
  if (newQueries.length > 0) {
152
151
  // It's actually fine to call this with queries/state that already exists
153
152
  // in the cache, or is older. hydrate() is idempotent for queries.
154
- // eslint-disable-next-line react-hooks/refs
153
+ // oxlint-disable-next-line react-hooks-js/refs
155
154
  hydrate(client, { queries: newQueries }, optionsRef.current)
156
155
  }
157
156
  if (existingQueries.length > 0) {
@@ -7,7 +7,6 @@ const IsRestoringContext = React.createContext(false)
7
7
  * If you are using `PersistQueryClientProvider`, you can also use the `useIsRestoring` hook alongside it to
8
8
  * check if a restore is currently in progress. `useQuery` and friends also check this internally to avoid
9
9
  * race conditions between the restore and mounting queries.
10
- *
11
10
  * @returns `true` while a persisted client is being restored, `false` otherwise.
12
11
  */
13
12
  export const useIsRestoring = () => React.useContext(IsRestoringContext)
@@ -12,11 +12,11 @@ export const QueryClientContext = React.createContext<QueryClient | undefined>(
12
12
 
13
13
  /**
14
14
  * The `useQueryClient` hook returns the current `QueryClient` instance.
15
- *
16
15
  * @param queryClient - Use this to use a custom `QueryClient`. Otherwise, the one from the nearest context will
17
16
  * be used.
18
17
  * @returns The current `QueryClient` instance.
19
- * @throws If no `queryClient` argument is passed and no `QueryClientProvider` is found in the component tree.
18
+ * @throws {Error} If no `queryClient` argument is passed and no `QueryClientProvider` is found in the
19
+ * component tree.
20
20
  */
21
21
  export const useQueryClient = (queryClient?: QueryClient) => {
22
22
  const client = React.useContext(QueryClientContext)
@@ -53,9 +53,8 @@ export type QueryClientProviderProps = {
53
53
  * calls `client.mount()`/`client.unmount()` as this component mounts/unmounts, which subscribes the client to
54
54
  * focus/online events (resuming any paused mutations and refetching as needed when the app regains focus or
55
55
  * comes back online).
56
- *
56
+ * @param props - The `client` to provide, and the `children` that get access to it.
57
57
  * @returns The provided `children`, wrapped so they can read the `QueryClient` via `useQueryClient`.
58
- *
59
58
  * @example
60
59
  * ```tsx
61
60
  * import { QueryClient, QueryClientProvider } from '@tanstack/react-query'
@@ -2,18 +2,45 @@
2
2
  import * as React from 'react'
3
3
 
4
4
  // CONTEXT
5
+
6
+ /**
7
+ * Resets any query errors within the boundary, so queries know they can try again.
8
+ */
5
9
  export type QueryErrorResetFunction = () => void
10
+
11
+ /**
12
+ * Returns whether the boundary has been reset and not yet cleared.
13
+ */
6
14
  export type QueryErrorIsResetFunction = () => boolean
15
+
16
+ /**
17
+ * Clears the reset state, so queries know not to try again until the boundary is reset again.
18
+ */
7
19
  export type QueryErrorClearResetFunction = () => void
8
20
 
21
+ /**
22
+ * The value a `QueryErrorResetBoundary` shares through context, used to reset query errors within
23
+ * it and to check whether a reset was requested.
24
+ */
9
25
  export interface QueryErrorResetBoundaryValue {
26
+ /**
27
+ * Clears the reset state, so queries know not to try again until the boundary is reset again.
28
+ */
10
29
  clearReset: QueryErrorClearResetFunction
30
+ /**
31
+ * Returns whether the boundary has been reset and not yet cleared.
32
+ */
11
33
  isReset: QueryErrorIsResetFunction
34
+ /**
35
+ * Resets any query errors within the boundary, so queries know they can try again.
36
+ */
12
37
  reset: QueryErrorResetFunction
13
38
  }
14
39
 
15
40
  /**
16
- * Resets any query errors within the boundary, so queries know they can try again.
41
+ * Creates the value shared through the boundary's context, which tracks whether a reset was
42
+ * requested.
43
+ * @returns The `clearReset`, `isReset`, and `reset` functions of the boundary.
17
44
  */
18
45
  function createValue(): QueryErrorResetBoundaryValue {
19
46
  let isReset = false
@@ -32,6 +59,7 @@ function createValue(): QueryErrorResetBoundaryValue {
32
59
  },
33
60
  /**
34
61
  * Returns whether the boundary has been reset and not yet cleared.
62
+ * @returns `true` if the boundary has been reset and not yet cleared.
35
63
  */
36
64
  isReset: () => {
37
65
  return isReset
@@ -46,9 +74,7 @@ const QueryErrorResetBoundaryContext = React.createContext(createValue())
46
74
  /**
47
75
  * This hook will reset any query errors within the closest `QueryErrorResetBoundary`. If there is no boundary
48
76
  * defined it will reset them globally.
49
- *
50
77
  * @returns The boundary's {@link QueryErrorResetBoundaryValue}.
51
- *
52
78
  * @example
53
79
  * ```tsx
54
80
  * import { ErrorBoundary } from 'react-error-boundary'
@@ -80,7 +106,6 @@ export const useQueryErrorResetBoundary = () =>
80
106
 
81
107
  /**
82
108
  * A render-prop function usable as `children` on `QueryErrorResetBoundary`.
83
- *
84
109
  * @param value - The boundary's {@link QueryErrorResetBoundaryValue}.
85
110
  * @returns The children to render.
86
111
  */
@@ -103,10 +128,9 @@ export interface QueryErrorResetBoundaryProps {
103
128
  * When using `suspense` or `throwOnError` in your queries, you need a way to let queries know that you want to
104
129
  * try again when re-rendering after some error occurred. With the `QueryErrorResetBoundary` component you can
105
130
  * reset any query errors within the boundaries of the component.
106
- *
131
+ * @param props - The `children` to render.
107
132
  * @returns The `children`, rendered as-is, or called with the boundary's {@link QueryErrorResetBoundaryValue}
108
133
  * if `children` is a function.
109
- *
110
134
  * @example
111
135
  * ```tsx
112
136
  * import { ErrorBoundary } from 'react-error-boundary'
@@ -10,6 +10,14 @@ import type {
10
10
  } from '@tanstack/query-core'
11
11
  import type { QueryErrorResetBoundaryValue } from './QueryErrorResetBoundary'
12
12
 
13
+ /**
14
+ * Turns off `retryOnMount` for a query that throws its errors (with `suspense` or `throwOnError`),
15
+ * unless the error boundary has been reset, so a remount doesn't retry the failed query before the
16
+ * user resets the boundary. Mutates the options.
17
+ * @param options - The defaulted query options to adjust.
18
+ * @param errorResetBoundary - The value of the nearest `QueryErrorResetBoundary`.
19
+ * @param query - The query, used to evaluate a `throwOnError` function against its error.
20
+ */
13
21
  export const ensurePreventErrorBoundaryRetry = <
14
22
  TQueryFnData,
15
23
  TError,
@@ -40,6 +48,11 @@ export const ensurePreventErrorBoundaryRetry = <
40
48
  }
41
49
  }
42
50
 
51
+ /**
52
+ * Clears the reset state of the error boundary after the component mounts, so later errors are
53
+ * thrown to the boundary again.
54
+ * @param errorResetBoundary - The value of the nearest `QueryErrorResetBoundary`.
55
+ */
43
56
  export const useClearResetErrorBoundary = (
44
57
  errorResetBoundary: QueryErrorResetBoundaryValue,
45
58
  ) => {
@@ -48,6 +61,14 @@ export const useClearResetErrorBoundary = (
48
61
  }, [errorResetBoundary])
49
62
  }
50
63
 
64
+ /**
65
+ * Checks whether the query error should be thrown to the nearest error boundary: the query errored
66
+ * and isn't fetching, the boundary hasn't been reset, and either `suspense` is enabled with no data
67
+ * or `throwOnError` says so.
68
+ * @param params - The observer `result`, the `errorResetBoundary`, the `throwOnError` option, the
69
+ * `query`, and the `suspense` option.
70
+ * @returns `true` if the error should be thrown.
71
+ */
51
72
  export const getHasError = <
52
73
  TData,
53
74
  TError,
@@ -13,7 +13,6 @@ import type { UseInfiniteQueryOptions } from './types'
13
13
  /**
14
14
  * The options accepted by the `infiniteQueryOptions` overload selected when no `initialData` is set — `data`
15
15
  * may be `undefined` while the query is `pending`.
16
- *
17
16
  * @template TQueryFnData - The type of a single page, as your `queryFn` resolves it.
18
17
  * @template TError - The type of errors your `queryFn` may throw.
19
18
  * @template TData - The type `data` ends up as after `select` runs — defaults to `InfiniteData<TQueryFnData>`,
@@ -53,7 +52,6 @@ export type UndefinedInitialDataInfiniteOptions<
53
52
  * The options accepted by the `infiniteQueryOptions` overload selected when no `initialData` is set and
54
53
  * `queryFn` is not `skipToken` — same as {@link UndefinedInitialDataInfiniteOptions}, but `queryFn` may not be
55
54
  * `skipToken`.
56
- *
57
55
  * @template TQueryFnData - The type of a single page, as your `queryFn` resolves it.
58
56
  * @template TError - The type of errors your `queryFn` may throw.
59
57
  * @template TData - The type `data` ends up as after `select` runs — defaults to `InfiniteData<TQueryFnData>`,
@@ -92,7 +90,6 @@ export type UnusedSkipTokenInfiniteOptions<
92
90
  /**
93
91
  * The options accepted by the `infiniteQueryOptions` overload selected when `initialData` is set — `data` is
94
92
  * never `undefined` (unless a `select` changes `TData` to include `undefined`).
95
- *
96
93
  * @template TQueryFnData - The type of a single page, as your `queryFn` resolves it.
97
94
  * @template TError - The type of errors your `queryFn` may throw.
98
95
  * @template TData - The type `data` ends up as after `select` runs — defaults to `InfiniteData<TQueryFnData>`,
@@ -132,13 +129,11 @@ export type DefinedInitialDataInfiniteOptions<
132
129
  * `options.queryKey` is required and is the query key to generate options for.
133
130
  *
134
131
  * This overload is selected when `initialData` is set.
135
- *
136
- * @see {@link useInfiniteQuery} to run an infinite query with these options.
137
132
  * @param options - The {@link DefinedInitialDataInfiniteOptions} to use — everything you can pass to `useInfiniteQuery`, with `initialData` set.
138
133
  * @returns The same options object, typed so that `queryKey` carries the inferred data type.
139
134
  * @remarks See {@link useInfiniteQuery} for examples that fetch further pages, from a button click or
140
135
  * automatically as the user scrolls.
141
- *
136
+ * @see {@link useInfiniteQuery} to run an infinite query with these options.
142
137
  * @example
143
138
  * ```tsx
144
139
  * import { infiniteQueryOptions, useInfiniteQuery } from '@tanstack/react-query'
@@ -194,11 +189,11 @@ export function infiniteQueryOptions<
194
189
  * You can generally pass everything to `infiniteQueryOptions` that you can also pass to `useInfiniteQuery`.
195
190
  * These options can be shared across hooks and imperative APIs such as `queryClient.infiniteQuery`.
196
191
  * `options.queryKey` is required and is the query key to generate options for.
197
- *
192
+ * @param options - The {@link UnusedSkipTokenInfiniteOptions} to use — everything you can pass to `useInfiniteQuery`.
198
193
  * @returns The same options object, typed so that `queryKey` carries the inferred data type.
199
194
  * @remarks See {@link useInfiniteQuery} for examples that fetch further pages, from a button click or
200
195
  * automatically as the user scrolls.
201
- *
196
+ * @see {@link useInfiniteQuery} to run an infinite query with these options.
202
197
  * @example
203
198
  * A parameterized factory, so the same options object can be reused per `postId`:
204
199
  * ```tsx
@@ -225,9 +220,6 @@ export function infiniteQueryOptions<
225
220
  * )
226
221
  * }
227
222
  * ```
228
- *
229
- * @see {@link useInfiniteQuery} to run an infinite query with these options.
230
- * @param options - The {@link UnusedSkipTokenInfiniteOptions} to use — everything you can pass to `useInfiniteQuery`.
231
223
  */
232
224
  export function infiniteQueryOptions<
233
225
  TQueryFnData,
@@ -256,11 +248,11 @@ export function infiniteQueryOptions<
256
248
  * You can generally pass everything to `infiniteQueryOptions` that you can also pass to `useInfiniteQuery`.
257
249
  * These options can be shared across hooks and imperative APIs such as `queryClient.infiniteQuery`.
258
250
  * `options.queryKey` is required and is the query key to generate options for.
259
- *
251
+ * @param options - The {@link UndefinedInitialDataInfiniteOptions} to use — everything you can pass to `useInfiniteQuery`.
260
252
  * @returns The same options object, typed so that `queryKey` carries the inferred data type.
261
253
  * @remarks See {@link useInfiniteQuery} for examples that fetch further pages (from a button click or
262
254
  * automatically as the user scrolls) and that use `skipToken` to disable the query until `postId` is set.
263
- *
255
+ * @see {@link useInfiniteQuery} to run an infinite query with these options.
264
256
  * @example
265
257
  * A parameterized factory, so the same options object can be reused per `postId`:
266
258
  * ```tsx
@@ -287,9 +279,6 @@ export function infiniteQueryOptions<
287
279
  * )
288
280
  * }
289
281
  * ```
290
- *
291
- * @see {@link useInfiniteQuery} to run an infinite query with these options.
292
- * @param options - The {@link UndefinedInitialDataInfiniteOptions} to use — everything you can pass to `useInfiniteQuery`.
293
282
  */
294
283
  export function infiniteQueryOptions<
295
284
  TQueryFnData,
@@ -5,12 +5,10 @@ import type { UseMutationOptions } from './types'
5
5
  * You can generally pass everything to `mutationOptions` that you can also pass to `useMutation`. A
6
6
  * `mutationKey` is required on this overload so the mutation can be looked up later, e.g. with
7
7
  * `useMutationState`.
8
- *
9
- * @see {@link useMutation} to run the mutation these options describe.
10
8
  * @param options - The mutation options to use, identical to what you'd pass to `useMutation`, with a
11
9
  * required `mutationKey`.
12
10
  * @returns The same options object, unchanged.
13
- *
11
+ * @see {@link useMutation} to run the mutation these options describe.
14
12
  * @example
15
13
  * Looking the mutation up elsewhere via its `mutationKey`, e.g. for a global "saving…" indicator:
16
14
  * ```tsx
@@ -49,13 +47,11 @@ export function mutationOptions<
49
47
  * `mutationKey` is required on this overload — use this when you don't need to target the mutation via a
50
48
  * `mutationKey` filter later (e.g. with `useMutationState`); it can still be observed through other filters,
51
49
  * such as `status`.
52
- *
53
- * @see {@link useMutation} to run the mutation these options describe.
54
50
  * @param options - The mutation options to use, identical to what you'd pass to `useMutation`, without a
55
51
  * `mutationKey`.
56
52
  * @returns The same options object, unchanged.
57
53
  * @remarks See the other overload's example for looking a mutation up via `useMutationState`.
58
- *
54
+ * @see {@link useMutation} to run the mutation these options describe.
59
55
  * @example
60
56
  * ```tsx
61
57
  * import { mutationOptions, useMutation } from '@tanstack/react-query'
@@ -13,7 +13,6 @@ import type { UseQueryOptions } from './types'
13
13
  /**
14
14
  * The options accepted by the `queryOptions` overload selected when no `initialData` is set — `data` may be
15
15
  * `undefined` while the query is `pending`.
16
- *
17
16
  * @template TQueryFnData - The type your `queryFn` resolves to.
18
17
  * @template TError - The type of errors your `queryFn` may throw.
19
18
  * @template TData - The type `data` ends up as after `select` runs.
@@ -41,7 +40,6 @@ export type UndefinedInitialDataOptions<
41
40
  /**
42
41
  * The options accepted by the `queryOptions` overload selected when no `initialData` is set and `queryFn` is
43
42
  * not `skipToken` — same as {@link UndefinedInitialDataOptions}, but `queryFn` may not be `skipToken`.
44
- *
45
43
  * @template TQueryFnData - The type your `queryFn` resolves to.
46
44
  * @template TError - The type of errors your `queryFn` may throw.
47
45
  * @template TData - The type `data` ends up as after `select` runs.
@@ -71,7 +69,6 @@ export type UnusedSkipTokenOptions<
71
69
  /**
72
70
  * The options accepted by the `queryOptions` overload selected when `initialData` is set — `data` is never
73
71
  * `undefined` (unless a `select` changes `TData` to include `undefined`).
74
- *
75
72
  * @template TQueryFnData - The type your `queryFn` resolves to.
76
73
  * @template TError - The type of errors your `queryFn` may throw.
77
74
  * @template TData - The type `data` ends up as after `select` runs.
@@ -91,7 +88,8 @@ export type DefinedInitialDataOptions<
91
88
  * cache.
92
89
  */
93
90
  initialData:
94
- NonUndefinedGuard<TQueryFnData> | (() => NonUndefinedGuard<TQueryFnData>)
91
+ | NonUndefinedGuard<TQueryFnData>
92
+ | (() => NonUndefinedGuard<TQueryFnData>)
95
93
  /**
96
94
  * Optional here, but omitting it is only safe when no fetch will be attempted — for example with
97
95
  * `enabled: false`, or when a default query function has been defined. Otherwise, an enabled query with no
@@ -107,12 +105,10 @@ export type DefinedInitialDataOptions<
107
105
  *
108
106
  * This overload is selected when `initialData` is set, so the resulting `data` is never `undefined` (unless
109
107
  * a `select` changes `TData` to include `undefined`).
110
- *
111
- * @see {@link useQuery} to run a query with these options.
112
- * @see [The Query Options API](https://tkdodo.eu/blog/the-query-options-api) for more on this pattern.
113
108
  * @param options - The {@link DefinedInitialDataOptions} to use — everything you can pass to `useQuery`, with `initialData` set.
114
109
  * @returns The same options object, typed so that `queryKey` carries the inferred data type.
115
- *
110
+ * @see {@link useQuery} to run a query with these options.
111
+ * @see [The Query Options API](https://tkdodo.eu/blog/the-query-options-api) for more on this pattern.
116
112
  * @example
117
113
  * ```tsx
118
114
  * import { queryOptions, useQuery } from '@tanstack/react-query'
@@ -153,12 +149,10 @@ export function queryOptions<
153
149
  * You can generally pass everything to `queryOptions` that you can also pass to `useQuery`. These options can
154
150
  * be shared across hooks and imperative APIs such as `queryClient.query`. `options.queryKey` is required and
155
151
  * is the query key to generate options for.
156
- *
157
- * @see {@link useQuery} to run a query with these options.
158
- * @see [The Query Options API](https://tkdodo.eu/blog/the-query-options-api) for more on this pattern.
159
152
  * @param options - The {@link UnusedSkipTokenOptions} to use — everything you can pass to `useQuery`.
160
153
  * @returns The same options object, typed so that `queryKey` carries the inferred data type.
161
- *
154
+ * @see {@link useQuery} to run a query with these options.
155
+ * @see [The Query Options API](https://tkdodo.eu/blog/the-query-options-api) for more on this pattern.
162
156
  * @example
163
157
  * A parameterized factory, so the same options object can be reused per `id`:
164
158
  * ```tsx
@@ -194,13 +188,11 @@ export function queryOptions<
194
188
  * You can generally pass everything to `queryOptions` that you can also pass to `useQuery`. These options can
195
189
  * be shared across hooks and imperative APIs such as `queryClient.query`. `options.queryKey` is required and
196
190
  * is the query key to generate options for.
197
- *
198
- * @see {@link useQuery} to run a query with these options.
199
- * @see [The Query Options API](https://tkdodo.eu/blog/the-query-options-api) for more on this pattern.
200
191
  * @param options - The {@link UndefinedInitialDataOptions} to use — everything you can pass to `useQuery`.
201
192
  * @returns The same options object, typed so that `queryKey` carries the inferred data type.
202
193
  * @remarks This is the only overload that accepts `queryFn: skipToken`, shown below.
203
- *
194
+ * @see {@link useQuery} to run a query with these options.
195
+ * @see [The Query Options API](https://tkdodo.eu/blog/the-query-options-api) for more on this pattern.
204
196
  * @example
205
197
  * A parameterized factory, so the same options object can be reused per `id`:
206
198
  * ```tsx
@@ -221,7 +213,6 @@ export function queryOptions<
221
213
  * return <h1>{data.title}</h1>
222
214
  * }
223
215
  * ```
224
- *
225
216
  * @example
226
217
  * A factory that disables the query, type safe, until `postId` is set:
227
218
  * ```tsx
package/src/suspense.ts CHANGED
@@ -8,6 +8,13 @@ import type {
8
8
  } from '@tanstack/query-core'
9
9
  import type { QueryErrorResetBoundaryValue } from './QueryErrorResetBoundary'
10
10
 
11
+ /**
12
+ * The default `throwOnError` of the suspense hooks: throws the error to the nearest error boundary
13
+ * only if the query has no data to show.
14
+ * @param _error - The error of the query. Unused.
15
+ * @param query - The query that errored.
16
+ * @returns `true` if the query has no data.
17
+ */
11
18
  export const defaultThrowOnError = <
12
19
  TQueryFnData = unknown,
13
20
  TError = DefaultError,
@@ -18,6 +25,12 @@ export const defaultThrowOnError = <
18
25
  query: Query<TQueryFnData, TError, TData, TQueryKey>,
19
26
  ) => query.state.data === undefined
20
27
 
28
+ /**
29
+ * Raises `staleTime` and a numeric `gcTime` to at least 1000ms when `suspense` is enabled, so a
30
+ * component that remounts after suspending doesn't refetch right away or find the query garbage
31
+ * collected. A `'static'` `staleTime` is kept as is. Mutates the options.
32
+ * @param defaultedOptions - The defaulted query options to adjust.
33
+ */
21
34
  export const ensureSuspenseTimers = (
22
35
  defaultedOptions: DefaultedQueryObserverOptions<any, any, any, any, any>,
23
36
  ) => {
@@ -46,12 +59,27 @@ export const ensureSuspenseTimers = (
46
59
  }
47
60
  }
48
61
 
62
+ /**
63
+ * Checks whether a query should suspend: `suspense` is enabled and the result is still `pending`.
64
+ * @param defaultedOptions - The defaulted query options, if any.
65
+ * @param result - The current result of the observer.
66
+ * @returns `true` if the component should suspend.
67
+ */
49
68
  export const shouldSuspend = (
50
69
  defaultedOptions:
51
- DefaultedQueryObserverOptions<any, any, any, any, any> | undefined,
70
+ | DefaultedQueryObserverOptions<any, any, any, any, any>
71
+ | undefined,
52
72
  result: QueryObserverResult<any, any>,
53
73
  ) => defaultedOptions?.suspense && result.isPending
54
74
 
75
+ /**
76
+ * Fetches the query for a suspending component, without affecting the observer's own result. If
77
+ * the fetch fails, the reset state of the error boundary is cleared, so the error is thrown to it.
78
+ * @param defaultedOptions - The defaulted query options to fetch with.
79
+ * @param observer - The observer of the query.
80
+ * @param errorResetBoundary - The value of the nearest `QueryErrorResetBoundary`.
81
+ * @returns A promise that resolves once the fetch settles. It never rejects.
82
+ */
55
83
  export const fetchOptimistic = <
56
84
  TQueryFnData,
57
85
  TError,
package/src/types.ts CHANGED
@@ -35,7 +35,6 @@ export type AnyUseBaseQueryOptions = UseBaseQueryOptions<
35
35
  /**
36
36
  * The options shared by `useQuery` and `useSuspenseQuery`. Extends {@link QueryObserverOptions} from
37
37
  * `@tanstack/query-core` with the `react-query`-specific `subscribed` option.
38
- *
39
38
  * @template TQueryFnData - The type your `queryFn` resolves to.
40
39
  * @template TError - The type of errors your `queryFn` may throw.
41
40
  * @template TData - The type `data` ends up as after `select` runs. Defaults to `TQueryFnData` when no
@@ -59,7 +58,6 @@ export interface UseBaseQueryOptions<
59
58
  > {
60
59
  /**
61
60
  * Set this to `false` to unsubscribe this observer from updates to the query cache.
62
- *
63
61
  * @defaultValue true
64
62
  */
65
63
  subscribed?: boolean
@@ -68,7 +66,6 @@ export interface UseBaseQueryOptions<
68
66
  /**
69
67
  * The options accepted by `usePrefetchQuery` — everything you can pass to `queryClient.query`, except `queryFn`
70
68
  * is required unless a default query function has been defined.
71
- *
72
69
  * @template TQueryFnData - The type your `queryFn` resolves to.
73
70
  * @template TError - The type of errors your `queryFn` may throw.
74
71
  * @template TData - The type `data` ends up as after `select` runs. Defaults to `TQueryFnData` when no
@@ -106,7 +103,6 @@ export type UsePrefetchQueryOptions<
106
103
  /**
107
104
  * The options accepted by `usePrefetchInfiniteQuery` — everything you can pass to `queryClient.infiniteQuery`,
108
105
  * except `queryFn` is required unless a default query function has been defined.
109
- *
110
106
  * @template TQueryFnData - The type of a single page, as your `queryFn` resolves it.
111
107
  * @template TError - The type of errors your `queryFn` may throw.
112
108
  * @template TData - The type `data` ends up as after `select` runs. Defaults to `InfiniteData<TQueryFnData>`,
@@ -155,7 +151,6 @@ export type AnyUseQueryOptions = UseQueryOptions<any, any, any, any>
155
151
  /**
156
152
  * The options accepted by `useQuery`. Same as {@link UseBaseQueryOptions}, minus `suspense` (which
157
153
  * `react-query` derives from which hook you call rather than exposing as an option).
158
- *
159
154
  * @template TQueryFnData - The type your `queryFn` resolves to.
160
155
  * @template TError - The type of errors your `queryFn` may throw.
161
156
  * @template TData - The type `data` ends up as after `select` runs. Defaults to `TQueryFnData` when no
@@ -186,7 +181,6 @@ export type AnyUseSuspenseQueryOptions = UseSuspenseQueryOptions<
186
181
  * The options accepted by `useSuspenseQuery`. Same as {@link UseQueryOptions}, minus `enabled`, `throwOnError`,
187
182
  * and `placeholderData` — Suspense hooks cannot render a "disabled" or "placeholder" state, so those options
188
183
  * don't apply.
189
- *
190
184
  * @template TQueryFnData - The type your `queryFn` resolves to.
191
185
  * @template TError - The type of errors your `queryFn` may throw.
192
186
  * @template TData - The type `data` ends up as after `select` runs. Defaults to `TQueryFnData` when no
@@ -227,7 +221,6 @@ export type AnyUseInfiniteQueryOptions = UseInfiniteQueryOptions<
227
221
  * The options accepted by `useInfiniteQuery`. Extends {@link InfiniteQueryObserverOptions} from
228
222
  * `@tanstack/query-core` with the `react-query`-specific `subscribed` option, minus `suspense` (which
229
223
  * `react-query` derives from which hook you call rather than exposing as an option).
230
- *
231
224
  * @template TQueryFnData - The type of a single page, as your `queryFn` resolves it.
232
225
  * @template TError - The type of errors your `queryFn` may throw.
233
226
  * @template TData - The type `data` ends up as after `select` runs — defaults to `InfiniteData<TQueryFnData>`,
@@ -253,7 +246,6 @@ export interface UseInfiniteQueryOptions<
253
246
  > {
254
247
  /**
255
248
  * Set this to `false` to unsubscribe this observer from updates to the query cache.
256
- *
257
249
  * @defaultValue true
258
250
  */
259
251
  subscribed?: boolean
@@ -269,7 +261,6 @@ export type AnyUseSuspenseInfiniteQueryOptions =
269
261
  * The options accepted by `useSuspenseInfiniteQuery`. Same as {@link UseInfiniteQueryOptions}, minus `enabled`,
270
262
  * `throwOnError`, and `placeholderData` — Suspense hooks cannot render a "disabled" or "placeholder" state, so
271
263
  * those options don't apply.
272
- *
273
264
  * @template TQueryFnData - The type of a single page, as your `queryFn` resolves it.
274
265
  * @template TError - The type of errors your `queryFn` may throw.
275
266
  * @template TData - The type `data` ends up as after `select` runs — defaults to `InfiniteData<TQueryFnData>`,
@@ -307,7 +298,6 @@ export interface UseSuspenseInfiniteQueryOptions<
307
298
  * The result of `useQuery` when `initialData` isn't set — `data` may be `undefined` while the query is
308
299
  * `pending`. Re-exports {@link QueryObserverResult} from `@tanstack/query-core`. `useInfiniteQuery` returns
309
300
  * {@link UseInfiniteQueryResult} instead.
310
- *
311
301
  * @template TData - The type `data` ends up as after `select` runs.
312
302
  * @template TError - The type of errors your `queryFn` may throw.
313
303
  */
@@ -318,7 +308,6 @@ export type UseBaseQueryResult<
318
308
 
319
309
  /**
320
310
  * The result of `useQuery`. Same as {@link UseBaseQueryResult}.
321
- *
322
311
  * @template TData - The type `data` ends up as after `select` runs.
323
312
  * @template TError - The type of errors your `queryFn` may throw.
324
313
  */
@@ -330,7 +319,6 @@ export type UseQueryResult<
330
319
  /**
331
320
  * The result of `useSuspenseQuery`. Same as {@link DefinedUseQueryResult}, minus `isPlaceholderData` — always
332
321
  * `false` on that type, so this drops the dead field rather than an active state.
333
- *
334
322
  * @template TData - The type `data` ends up as after `select` runs.
335
323
  * @template TError - The type of errors your `queryFn` may throw.
336
324
  */
@@ -346,7 +334,6 @@ export type UseSuspenseQueryResult<
346
334
  * The result of `useQuery` when `initialData` is set, or of `useSuspenseQuery` before the `isPlaceholderData`
347
335
  * omission — `data` is never `undefined` (unless a `select` changes `TData` to include `undefined`).
348
336
  * Re-exports {@link DefinedQueryObserverResult} from `@tanstack/query-core`.
349
- *
350
337
  * @template TData - The type `data` ends up as after `select` runs.
351
338
  * @template TError - The type of errors your `queryFn` may throw.
352
339
  */
@@ -358,7 +345,6 @@ export type DefinedUseQueryResult<
358
345
  /**
359
346
  * The result of `useInfiniteQuery` when `initialData` isn't set — `data` may be `undefined` while the query is
360
347
  * `pending`. Re-exports {@link InfiniteQueryObserverResult} from `@tanstack/query-core`.
361
- *
362
348
  * @template TData - The type `data` ends up as after `select` runs.
363
349
  * @template TError - The type of errors your `queryFn` may throw.
364
350
  */
@@ -371,7 +357,6 @@ export type UseInfiniteQueryResult<
371
357
  * The result of `useInfiniteQuery` when `initialData` is set — `data` is never `undefined` (unless a
372
358
  * `select` changes `TData` to include `undefined`). Re-exports {@link DefinedInfiniteQueryObserverResult}
373
359
  * from `@tanstack/query-core`.
374
- *
375
360
  * @template TData - The type `data` ends up as after `select` runs.
376
361
  * @template TError - The type of errors your `queryFn` may throw.
377
362
  */
@@ -383,7 +368,6 @@ export type DefinedUseInfiniteQueryResult<
383
368
  /**
384
369
  * The result of `useSuspenseInfiniteQuery`. Same as {@link DefinedUseInfiniteQueryResult}, minus
385
370
  * `isPlaceholderData` — Suspense hooks never render placeholder data.
386
- *
387
371
  * @template TData - The type `data` ends up as after `select` runs.
388
372
  * @template TError - The type of errors your `queryFn` may throw.
389
373
  */
@@ -403,7 +387,6 @@ export type AnyUseMutationOptions = UseMutationOptions<any, any, any, any>
403
387
  /**
404
388
  * The options accepted by `useMutation`. Same as {@link MutationObserverOptions} from `@tanstack/query-core`,
405
389
  * minus the internal `_defaulted` flag.
406
- *
407
390
  * @template TData - The type your mutation function resolves to.
408
391
  * @template TError - The type of errors your mutation function may throw.
409
392
  * @template TVariables - The type of the variable passed to `mutate`/`mutateAsync`.
@@ -423,8 +406,8 @@ export interface UseMutationOptions<
423
406
  /**
424
407
  * The type of `mutate`, as returned by `useMutation`. Forwards the variables (and an optional per-call
425
408
  * `onSuccess`/`onError`/`onSettled`) to the underlying `mutate` call. Fire-and-forget — errors are surfaced
426
- * through the mutation result, not thrown.
427
- *
409
+ * through the mutation result instead of being thrown by `mutate`, unless `throwOnError` makes `useMutation`
410
+ * rethrow them.
428
411
  * @template TData - The type your mutation function resolves to.
429
412
  * @template TError - The type of errors your mutation function may throw.
430
413
  * @template TVariables - The type of the variable passed to `mutate`.
@@ -445,7 +428,6 @@ export type UseMutateFunction<
445
428
  /**
446
429
  * The type of `mutateAsync`, as returned by `useMutation`. Similar to {@link UseMutateFunction}, but returns a
447
430
  * promise which can be awaited.
448
- *
449
431
  * @template TData - The type your mutation function resolves to.
450
432
  * @template TError - The type of errors your mutation function may throw.
451
433
  * @template TVariables - The type of the variable passed to `mutateAsync`.
@@ -462,7 +444,6 @@ export type UseMutateAsyncFunction<
462
444
  /**
463
445
  * The result of `useMutation`. Same as {@link MutationObserverResult} from `@tanstack/query-core`, with
464
446
  * `mutate` narrowed to the fire-and-forget {@link UseMutateFunction} signature, plus the added `mutateAsync`.
465
- *
466
447
  * @template TData - The type your mutation function resolves to.
467
448
  * @template TError - The type of errors your mutation function may throw.
468
449
  * @template TVariables - The type of the variable passed to `mutate`/`mutateAsync`.
@@ -491,7 +472,6 @@ export type UseBaseMutationResult<
491
472
 
492
473
  /**
493
474
  * The result of `useMutation`. Same as {@link UseBaseMutationResult}.
494
- *
495
475
  * @template TData - The type your mutation function resolves to.
496
476
  * @template TError - The type of errors your mutation function may throw.
497
477
  * @template TVariables - The type of the variable passed to `mutate`/`mutateAsync`.