@tanstack/preact-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 (364) 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 +3 -4
  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 +4 -5
  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 +6 -4
  26. package/build/legacy/QueryErrorResetBoundary.cjs.map +1 -1
  27. package/build/legacy/QueryErrorResetBoundary.d.cts +5 -5
  28. package/build/legacy/QueryErrorResetBoundary.d.cts.map +1 -1
  29. package/build/legacy/QueryErrorResetBoundary.d.ts +5 -5
  30. package/build/legacy/QueryErrorResetBoundary.d.ts.map +1 -1
  31. package/build/legacy/QueryErrorResetBoundary.js +6 -4
  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 +3 -3
  128. package/build/legacy/useQueries.cjs.map +1 -1
  129. package/build/legacy/useQueries.d.cts +3 -6
  130. package/build/legacy/useQueries.d.cts.map +1 -1
  131. package/build/legacy/useQueries.d.ts +3 -6
  132. package/build/legacy/useQueries.d.ts.map +1 -1
  133. package/build/legacy/useQueries.js +3 -3
  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/legacy/utils.cjs +21 -1
  164. package/build/legacy/utils.cjs.map +1 -1
  165. package/build/legacy/utils.d.cts +15 -0
  166. package/build/legacy/utils.d.cts.map +1 -1
  167. package/build/legacy/utils.d.ts +15 -0
  168. package/build/legacy/utils.d.ts.map +1 -1
  169. package/build/legacy/utils.js +21 -1
  170. package/build/legacy/utils.js.map +1 -1
  171. package/build/modern/HydrationBoundary.cjs +2 -3
  172. package/build/modern/HydrationBoundary.cjs.map +1 -1
  173. package/build/modern/HydrationBoundary.d.cts +3 -4
  174. package/build/modern/HydrationBoundary.d.cts.map +1 -1
  175. package/build/modern/HydrationBoundary.d.ts +2 -3
  176. package/build/modern/HydrationBoundary.d.ts.map +1 -1
  177. package/build/modern/HydrationBoundary.js +2 -3
  178. package/build/modern/HydrationBoundary.js.map +1 -1
  179. package/build/modern/IsRestoringProvider.cjs +0 -1
  180. package/build/modern/IsRestoringProvider.cjs.map +1 -1
  181. package/build/modern/IsRestoringProvider.d.cts +0 -1
  182. package/build/modern/IsRestoringProvider.d.cts.map +1 -1
  183. package/build/modern/IsRestoringProvider.d.ts +0 -1
  184. package/build/modern/IsRestoringProvider.d.ts.map +1 -1
  185. package/build/modern/IsRestoringProvider.js +0 -1
  186. package/build/modern/IsRestoringProvider.js.map +1 -1
  187. package/build/modern/QueryClientProvider.cjs +3 -4
  188. package/build/modern/QueryClientProvider.cjs.map +1 -1
  189. package/build/modern/QueryClientProvider.d.cts +4 -5
  190. package/build/modern/QueryClientProvider.d.cts.map +1 -1
  191. package/build/modern/QueryClientProvider.d.ts +3 -4
  192. package/build/modern/QueryClientProvider.d.ts.map +1 -1
  193. package/build/modern/QueryClientProvider.js +3 -4
  194. package/build/modern/QueryClientProvider.js.map +1 -1
  195. package/build/modern/QueryErrorResetBoundary.cjs +6 -4
  196. package/build/modern/QueryErrorResetBoundary.cjs.map +1 -1
  197. package/build/modern/QueryErrorResetBoundary.d.cts +5 -5
  198. package/build/modern/QueryErrorResetBoundary.d.cts.map +1 -1
  199. package/build/modern/QueryErrorResetBoundary.d.ts +5 -5
  200. package/build/modern/QueryErrorResetBoundary.d.ts.map +1 -1
  201. package/build/modern/QueryErrorResetBoundary.js +6 -4
  202. package/build/modern/QueryErrorResetBoundary.js.map +1 -1
  203. package/build/modern/errorBoundaryUtils.cjs +21 -0
  204. package/build/modern/errorBoundaryUtils.cjs.map +1 -1
  205. package/build/modern/errorBoundaryUtils.d.cts +21 -0
  206. package/build/modern/errorBoundaryUtils.d.cts.map +1 -1
  207. package/build/modern/errorBoundaryUtils.d.ts +21 -0
  208. package/build/modern/errorBoundaryUtils.d.ts.map +1 -1
  209. package/build/modern/errorBoundaryUtils.js +21 -0
  210. package/build/modern/errorBoundaryUtils.js.map +1 -1
  211. package/build/modern/infiniteQueryOptions.cjs.map +1 -1
  212. package/build/modern/infiniteQueryOptions.d.cts +5 -16
  213. package/build/modern/infiniteQueryOptions.d.cts.map +1 -1
  214. package/build/modern/infiniteQueryOptions.d.ts +5 -16
  215. package/build/modern/infiniteQueryOptions.d.ts.map +1 -1
  216. package/build/modern/infiniteQueryOptions.js.map +1 -1
  217. package/build/modern/mutationOptions.cjs.map +1 -1
  218. package/build/modern/mutationOptions.d.cts +2 -6
  219. package/build/modern/mutationOptions.d.cts.map +1 -1
  220. package/build/modern/mutationOptions.d.ts +2 -6
  221. package/build/modern/mutationOptions.d.ts.map +1 -1
  222. package/build/modern/mutationOptions.js.map +1 -1
  223. package/build/modern/queryOptions.cjs.map +1 -1
  224. package/build/modern/queryOptions.d.cts +6 -16
  225. package/build/modern/queryOptions.d.cts.map +1 -1
  226. package/build/modern/queryOptions.d.ts +6 -16
  227. package/build/modern/queryOptions.d.ts.map +1 -1
  228. package/build/modern/queryOptions.js.map +1 -1
  229. package/build/modern/suspense.cjs +27 -0
  230. package/build/modern/suspense.cjs.map +1 -1
  231. package/build/modern/suspense.d.cts +27 -0
  232. package/build/modern/suspense.d.cts.map +1 -1
  233. package/build/modern/suspense.d.ts +27 -0
  234. package/build/modern/suspense.d.ts.map +1 -1
  235. package/build/modern/suspense.js +27 -0
  236. package/build/modern/suspense.js.map +1 -1
  237. package/build/modern/types.cjs.map +1 -1
  238. package/build/modern/types.d.cts +2 -22
  239. package/build/modern/types.d.cts.map +1 -1
  240. package/build/modern/types.d.ts +2 -22
  241. package/build/modern/types.d.ts.map +1 -1
  242. package/build/modern/types.js.map +1 -1
  243. package/build/modern/useBaseQuery.cjs +13 -0
  244. package/build/modern/useBaseQuery.cjs.map +1 -1
  245. package/build/modern/useBaseQuery.d.cts +13 -0
  246. package/build/modern/useBaseQuery.d.cts.map +1 -1
  247. package/build/modern/useBaseQuery.d.ts +13 -0
  248. package/build/modern/useBaseQuery.d.ts.map +1 -1
  249. package/build/modern/useBaseQuery.js +13 -0
  250. package/build/modern/useBaseQuery.js.map +1 -1
  251. package/build/modern/useInfiniteQuery.cjs.map +1 -1
  252. package/build/modern/useInfiniteQuery.d.cts +12 -21
  253. package/build/modern/useInfiniteQuery.d.cts.map +1 -1
  254. package/build/modern/useInfiniteQuery.d.ts +12 -21
  255. package/build/modern/useInfiniteQuery.d.ts.map +1 -1
  256. package/build/modern/useInfiniteQuery.js.map +1 -1
  257. package/build/modern/useIsFetching.cjs +0 -3
  258. package/build/modern/useIsFetching.cjs.map +1 -1
  259. package/build/modern/useIsFetching.d.cts +0 -3
  260. package/build/modern/useIsFetching.d.cts.map +1 -1
  261. package/build/modern/useIsFetching.d.ts +0 -3
  262. package/build/modern/useIsFetching.d.ts.map +1 -1
  263. package/build/modern/useIsFetching.js +0 -3
  264. package/build/modern/useIsFetching.js.map +1 -1
  265. package/build/modern/useMutation.cjs +4 -8
  266. package/build/modern/useMutation.cjs.map +1 -1
  267. package/build/modern/useMutation.d.cts +4 -8
  268. package/build/modern/useMutation.d.cts.map +1 -1
  269. package/build/modern/useMutation.d.ts +4 -8
  270. package/build/modern/useMutation.d.ts.map +1 -1
  271. package/build/modern/useMutation.js +4 -8
  272. package/build/modern/useMutation.js.map +1 -1
  273. package/build/modern/useMutationState.cjs +7 -6
  274. package/build/modern/useMutationState.cjs.map +1 -1
  275. package/build/modern/useMutationState.d.cts +0 -6
  276. package/build/modern/useMutationState.d.cts.map +1 -1
  277. package/build/modern/useMutationState.d.ts +0 -6
  278. package/build/modern/useMutationState.d.ts.map +1 -1
  279. package/build/modern/useMutationState.js +7 -6
  280. package/build/modern/useMutationState.js.map +1 -1
  281. package/build/modern/usePrefetchInfiniteQuery.cjs +0 -3
  282. package/build/modern/usePrefetchInfiniteQuery.cjs.map +1 -1
  283. package/build/modern/usePrefetchInfiniteQuery.d.cts +0 -3
  284. package/build/modern/usePrefetchInfiniteQuery.d.cts.map +1 -1
  285. package/build/modern/usePrefetchInfiniteQuery.d.ts +0 -3
  286. package/build/modern/usePrefetchInfiniteQuery.d.ts.map +1 -1
  287. package/build/modern/usePrefetchInfiniteQuery.js +0 -3
  288. package/build/modern/usePrefetchInfiniteQuery.js.map +1 -1
  289. package/build/modern/usePrefetchQuery.cjs +0 -3
  290. package/build/modern/usePrefetchQuery.cjs.map +1 -1
  291. package/build/modern/usePrefetchQuery.d.cts +0 -3
  292. package/build/modern/usePrefetchQuery.d.cts.map +1 -1
  293. package/build/modern/usePrefetchQuery.d.ts +0 -3
  294. package/build/modern/usePrefetchQuery.d.ts.map +1 -1
  295. package/build/modern/usePrefetchQuery.js +0 -3
  296. package/build/modern/usePrefetchQuery.js.map +1 -1
  297. package/build/modern/useQueries.cjs +3 -3
  298. package/build/modern/useQueries.cjs.map +1 -1
  299. package/build/modern/useQueries.d.cts +3 -6
  300. package/build/modern/useQueries.d.cts.map +1 -1
  301. package/build/modern/useQueries.d.ts +3 -6
  302. package/build/modern/useQueries.d.ts.map +1 -1
  303. package/build/modern/useQueries.js +3 -3
  304. package/build/modern/useQueries.js.map +1 -1
  305. package/build/modern/useQuery.cjs.map +1 -1
  306. package/build/modern/useQuery.d.cts +8 -13
  307. package/build/modern/useQuery.d.cts.map +1 -1
  308. package/build/modern/useQuery.d.ts +8 -13
  309. package/build/modern/useQuery.d.ts.map +1 -1
  310. package/build/modern/useQuery.js.map +1 -1
  311. package/build/modern/useSuspenseInfiniteQuery.cjs +6 -8
  312. package/build/modern/useSuspenseInfiniteQuery.cjs.map +1 -1
  313. package/build/modern/useSuspenseInfiniteQuery.d.cts +6 -8
  314. package/build/modern/useSuspenseInfiniteQuery.d.cts.map +1 -1
  315. package/build/modern/useSuspenseInfiniteQuery.d.ts +6 -8
  316. package/build/modern/useSuspenseInfiniteQuery.d.ts.map +1 -1
  317. package/build/modern/useSuspenseInfiniteQuery.js +6 -8
  318. package/build/modern/useSuspenseInfiniteQuery.js.map +1 -1
  319. package/build/modern/useSuspenseQueries.cjs.map +1 -1
  320. package/build/modern/useSuspenseQueries.d.cts +0 -9
  321. package/build/modern/useSuspenseQueries.d.cts.map +1 -1
  322. package/build/modern/useSuspenseQueries.d.ts +0 -9
  323. package/build/modern/useSuspenseQueries.d.ts.map +1 -1
  324. package/build/modern/useSuspenseQueries.js.map +1 -1
  325. package/build/modern/useSuspenseQuery.cjs +4 -6
  326. package/build/modern/useSuspenseQuery.cjs.map +1 -1
  327. package/build/modern/useSuspenseQuery.d.cts +4 -6
  328. package/build/modern/useSuspenseQuery.d.cts.map +1 -1
  329. package/build/modern/useSuspenseQuery.d.ts +4 -6
  330. package/build/modern/useSuspenseQuery.d.ts.map +1 -1
  331. package/build/modern/useSuspenseQuery.js +4 -6
  332. package/build/modern/useSuspenseQuery.js.map +1 -1
  333. package/build/modern/utils.cjs +21 -1
  334. package/build/modern/utils.cjs.map +1 -1
  335. package/build/modern/utils.d.cts +15 -0
  336. package/build/modern/utils.d.cts.map +1 -1
  337. package/build/modern/utils.d.ts +15 -0
  338. package/build/modern/utils.d.ts.map +1 -1
  339. package/build/modern/utils.js +21 -1
  340. package/build/modern/utils.js.map +1 -1
  341. package/package.json +8 -10
  342. package/src/HydrationBoundary.tsx +8 -8
  343. package/src/IsRestoringProvider.ts +0 -1
  344. package/src/QueryClientProvider.tsx +5 -6
  345. package/src/QueryErrorResetBoundary.tsx +11 -6
  346. package/src/errorBoundaryUtils.ts +22 -1
  347. package/src/infiniteQueryOptions.ts +5 -16
  348. package/src/mutationOptions.ts +2 -6
  349. package/src/queryOptions.ts +8 -17
  350. package/src/suspense.ts +29 -1
  351. package/src/types.ts +2 -22
  352. package/src/useBaseQuery.ts +20 -7
  353. package/src/useInfiniteQuery.ts +13 -22
  354. package/src/useIsFetching.ts +1 -4
  355. package/src/useMutation.ts +6 -10
  356. package/src/useMutationState.ts +11 -10
  357. package/src/usePrefetchInfiniteQuery.tsx +0 -3
  358. package/src/usePrefetchQuery.tsx +0 -3
  359. package/src/useQueries.ts +15 -18
  360. package/src/useQuery.ts +9 -14
  361. package/src/useSuspenseInfiniteQuery.ts +8 -10
  362. package/src/useSuspenseQueries.ts +2 -11
  363. package/src/useSuspenseQuery.ts +6 -8
  364. package/src/utils.ts +21 -1
package/src/suspense.ts CHANGED
@@ -9,6 +9,13 @@ import type {
9
9
 
10
10
  import type { QueryErrorResetBoundaryValue } from './QueryErrorResetBoundary'
11
11
 
12
+ /**
13
+ * The default `throwOnError` of the suspense hooks: throws the error to the nearest error boundary
14
+ * only if the query has no data to show.
15
+ * @param _error - The error of the query. Unused.
16
+ * @param query - The query that errored.
17
+ * @returns `true` if the query has no data.
18
+ */
12
19
  export const defaultThrowOnError = <
13
20
  TQueryFnData = unknown,
14
21
  TError = DefaultError,
@@ -19,6 +26,12 @@ export const defaultThrowOnError = <
19
26
  query: Query<TQueryFnData, TError, TData, TQueryKey>,
20
27
  ) => query.state.data === undefined
21
28
 
29
+ /**
30
+ * Raises `staleTime` and a numeric `gcTime` to at least 1000ms when `suspense` is enabled, so a
31
+ * component that remounts after suspending doesn't refetch right away or find the query garbage
32
+ * collected. A `'static'` `staleTime` is kept as is. Mutates the options.
33
+ * @param defaultedOptions - The defaulted query options to adjust.
34
+ */
22
35
  export const ensureSuspenseTimers = (
23
36
  defaultedOptions: DefaultedQueryObserverOptions<any, any, any, any, any>,
24
37
  ) => {
@@ -47,12 +60,27 @@ export const ensureSuspenseTimers = (
47
60
  }
48
61
  }
49
62
 
63
+ /**
64
+ * Checks whether a query should suspend: `suspense` is enabled and the result is still `pending`.
65
+ * @param defaultedOptions - The defaulted query options, if any.
66
+ * @param result - The current result of the observer.
67
+ * @returns `true` if the component should suspend.
68
+ */
50
69
  export const shouldSuspend = (
51
70
  defaultedOptions:
52
- DefaultedQueryObserverOptions<any, any, any, any, any> | undefined,
71
+ | DefaultedQueryObserverOptions<any, any, any, any, any>
72
+ | undefined,
53
73
  result: QueryObserverResult<any, any>,
54
74
  ) => defaultedOptions?.suspense && result.isPending
55
75
 
76
+ /**
77
+ * Fetches the query for a suspending component, without affecting the observer's own result. If
78
+ * the fetch fails, the reset state of the error boundary is cleared, so the error is thrown to it.
79
+ * @param defaultedOptions - The defaulted query options to fetch with.
80
+ * @param observer - The observer of the query.
81
+ * @param errorResetBoundary - The value of the nearest `QueryErrorResetBoundary`.
82
+ * @returns A promise that resolves once the fetch settles. It never rejects.
83
+ */
56
84
  export const fetchOptimistic = <
57
85
  TQueryFnData,
58
86
  TError,
package/src/types.ts CHANGED
@@ -34,7 +34,6 @@ export type AnyUseBaseQueryOptions = UseBaseQueryOptions<
34
34
  /**
35
35
  * The options shared by `useQuery` and `useSuspenseQuery`. Extends {@link QueryObserverOptions} from
36
36
  * `@tanstack/query-core` with the `preact-query`-specific `subscribed` option.
37
- *
38
37
  * @template TQueryFnData - The type your `queryFn` resolves to.
39
38
  * @template TError - The type of errors your `queryFn` may throw.
40
39
  * @template TData - The type `data` ends up as after `select` runs. Defaults to `TQueryFnData` when no
@@ -58,7 +57,6 @@ export interface UseBaseQueryOptions<
58
57
  > {
59
58
  /**
60
59
  * Set this to `false` to unsubscribe this observer from updates to the query cache.
61
- *
62
60
  * @defaultValue true
63
61
  */
64
62
  subscribed?: boolean
@@ -67,7 +65,6 @@ export interface UseBaseQueryOptions<
67
65
  /**
68
66
  * The options accepted by `usePrefetchQuery` — everything you can pass to `queryClient.query`, except `queryFn`
69
67
  * is required unless a default query function has been defined.
70
- *
71
68
  * @template TQueryFnData - The type your `queryFn` resolves to.
72
69
  * @template TError - The type of errors your `queryFn` may throw.
73
70
  * @template TData - The type `data` ends up as after `select` runs. Defaults to `TQueryFnData` when no
@@ -105,7 +102,6 @@ export type UsePrefetchQueryOptions<
105
102
  /**
106
103
  * The options accepted by `usePrefetchInfiniteQuery` — everything you can pass to `queryClient.infiniteQuery`,
107
104
  * except `queryFn` is required unless a default query function has been defined.
108
- *
109
105
  * @template TQueryFnData - The type of a single page, as your `queryFn` resolves it.
110
106
  * @template TError - The type of errors your `queryFn` may throw.
111
107
  * @template TData - The type `data` ends up as after `select` runs. Defaults to `TQueryFnData` (a single page)
@@ -154,7 +150,6 @@ export type AnyUseQueryOptions = UseQueryOptions<any, any, any, any>
154
150
  /**
155
151
  * The options accepted by `useQuery`. Same as {@link UseBaseQueryOptions}, minus `suspense` (which
156
152
  * `preact-query` derives from which hook you call rather than exposing as an option).
157
- *
158
153
  * @template TQueryFnData - The type your `queryFn` resolves to.
159
154
  * @template TError - The type of errors your `queryFn` may throw.
160
155
  * @template TData - The type `data` ends up as after `select` runs. Defaults to `TQueryFnData` when no
@@ -185,7 +180,6 @@ export type AnyUseSuspenseQueryOptions = UseSuspenseQueryOptions<
185
180
  * The options accepted by `useSuspenseQuery`. Same as {@link UseQueryOptions}, minus `enabled`, `throwOnError`,
186
181
  * and `placeholderData` — Suspense hooks cannot render a "disabled" or "placeholder" state, so those options
187
182
  * don't apply.
188
- *
189
183
  * @template TQueryFnData - The type your `queryFn` resolves to.
190
184
  * @template TError - The type of errors your `queryFn` may throw.
191
185
  * @template TData - The type `data` ends up as after `select` runs. Defaults to `TQueryFnData` when no
@@ -226,7 +220,6 @@ export type AnyUseInfiniteQueryOptions = UseInfiniteQueryOptions<
226
220
  * The options accepted by `useInfiniteQuery`. Extends {@link InfiniteQueryObserverOptions} from
227
221
  * `@tanstack/query-core` with the `preact-query`-specific `subscribed` option, minus `suspense` (which
228
222
  * `preact-query` derives from which hook you call rather than exposing as an option).
229
- *
230
223
  * @template TQueryFnData - The type of a single page, as your `queryFn` resolves it.
231
224
  * @template TError - The type of errors your `queryFn` may throw.
232
225
  * @template TData - The type `data` ends up as after `select` runs — defaults to `InfiniteData<TQueryFnData>`,
@@ -252,7 +245,6 @@ export interface UseInfiniteQueryOptions<
252
245
  > {
253
246
  /**
254
247
  * Set this to `false` to unsubscribe this observer from updates to the query cache.
255
- *
256
248
  * @defaultValue true
257
249
  */
258
250
  subscribed?: boolean
@@ -268,7 +260,6 @@ export type AnyUseSuspenseInfiniteQueryOptions =
268
260
  * The options accepted by `useSuspenseInfiniteQuery`. Same as {@link UseInfiniteQueryOptions}, minus `enabled`,
269
261
  * `throwOnError`, and `placeholderData` — Suspense hooks cannot render a "disabled" or "placeholder" state, so
270
262
  * those options don't apply.
271
- *
272
263
  * @template TQueryFnData - The type of a single page, as your `queryFn` resolves it.
273
264
  * @template TError - The type of errors your `queryFn` may throw.
274
265
  * @template TData - The type `data` ends up as after `select` runs — defaults to `InfiniteData<TQueryFnData>`,
@@ -306,7 +297,6 @@ export interface UseSuspenseInfiniteQueryOptions<
306
297
  * The result of `useQuery` when `initialData` isn't set — `data` may be `undefined` while the query is
307
298
  * `pending`. Re-exports {@link QueryObserverResult} from `@tanstack/query-core`. `useInfiniteQuery` returns
308
299
  * {@link UseInfiniteQueryResult} instead.
309
- *
310
300
  * @template TData - The type `data` ends up as after `select` runs.
311
301
  * @template TError - The type of errors your `queryFn` may throw.
312
302
  */
@@ -317,7 +307,6 @@ export type UseBaseQueryResult<
317
307
 
318
308
  /**
319
309
  * The result of `useQuery`. Same as {@link UseBaseQueryResult}.
320
- *
321
310
  * @template TData - The type `data` ends up as after `select` runs.
322
311
  * @template TError - The type of errors your `queryFn` may throw.
323
312
  */
@@ -329,7 +318,6 @@ export type UseQueryResult<
329
318
  /**
330
319
  * The result of `useSuspenseQuery`. Same as {@link DefinedUseQueryResult}, minus `isPlaceholderData` — always
331
320
  * `false` on that type, so this drops the dead field rather than an active state.
332
- *
333
321
  * @template TData - The type `data` ends up as after `select` runs.
334
322
  * @template TError - The type of errors your `queryFn` may throw.
335
323
  */
@@ -345,7 +333,6 @@ export type UseSuspenseQueryResult<
345
333
  * The result of `useQuery` when `initialData` is set, or of `useSuspenseQuery` before the `isPlaceholderData`
346
334
  * omission — `data` is never `undefined` (unless a `select` changes `TData` to include `undefined`).
347
335
  * Re-exports {@link DefinedQueryObserverResult} from `@tanstack/query-core`.
348
- *
349
336
  * @template TData - The type `data` ends up as after `select` runs.
350
337
  * @template TError - The type of errors your `queryFn` may throw.
351
338
  */
@@ -357,7 +344,6 @@ export type DefinedUseQueryResult<
357
344
  /**
358
345
  * The result of `useInfiniteQuery` when `initialData` isn't set — `data` may be `undefined` while the query is
359
346
  * `pending`. Re-exports {@link InfiniteQueryObserverResult} from `@tanstack/query-core`.
360
- *
361
347
  * @template TData - The type `data` ends up as after `select` runs.
362
348
  * @template TError - The type of errors your `queryFn` may throw.
363
349
  */
@@ -370,7 +356,6 @@ export type UseInfiniteQueryResult<
370
356
  * The result of `useInfiniteQuery` when `initialData` is set — `data` is never `undefined` (unless a
371
357
  * `select` changes `TData` to include `undefined`). Re-exports {@link DefinedInfiniteQueryObserverResult}
372
358
  * from `@tanstack/query-core`.
373
- *
374
359
  * @template TData - The type `data` ends up as after `select` runs.
375
360
  * @template TError - The type of errors your `queryFn` may throw.
376
361
  */
@@ -382,7 +367,6 @@ export type DefinedUseInfiniteQueryResult<
382
367
  /**
383
368
  * The result of `useSuspenseInfiniteQuery`. Same as {@link DefinedUseInfiniteQueryResult}, minus
384
369
  * `isPlaceholderData` — Suspense hooks never render placeholder data.
385
- *
386
370
  * @template TData - The type `data` ends up as after `select` runs.
387
371
  * @template TError - The type of errors your `queryFn` may throw.
388
372
  */
@@ -402,7 +386,6 @@ export type AnyUseMutationOptions = UseMutationOptions<any, any, any, any>
402
386
  /**
403
387
  * The options accepted by `useMutation`. Same as {@link MutationObserverOptions} from `@tanstack/query-core`,
404
388
  * minus the internal `_defaulted` flag.
405
- *
406
389
  * @template TData - The type your mutation function resolves to.
407
390
  * @template TError - The type of errors your mutation function may throw.
408
391
  * @template TVariables - The type of the variable passed to `mutate`/`mutateAsync`.
@@ -422,8 +405,8 @@ export interface UseMutationOptions<
422
405
  /**
423
406
  * The type of `mutate`, as returned by `useMutation`. Forwards the variables (and an optional per-call
424
407
  * `onSuccess`/`onError`/`onSettled`) to the underlying `mutate` call. Fire-and-forget — errors are surfaced
425
- * through the mutation result, not thrown.
426
- *
408
+ * through the mutation result instead of being thrown by `mutate`, unless `throwOnError` makes `useMutation`
409
+ * rethrow them.
427
410
  * @template TData - The type your mutation function resolves to.
428
411
  * @template TError - The type of errors your mutation function may throw.
429
412
  * @template TVariables - The type of the variable passed to `mutate`.
@@ -444,7 +427,6 @@ export type UseMutateFunction<
444
427
  /**
445
428
  * The type of `mutateAsync`, as returned by `useMutation`. Similar to {@link UseMutateFunction}, but returns a
446
429
  * promise which can be awaited.
447
- *
448
430
  * @template TData - The type your mutation function resolves to.
449
431
  * @template TError - The type of errors your mutation function may throw.
450
432
  * @template TVariables - The type of the variable passed to `mutateAsync`.
@@ -461,7 +443,6 @@ export type UseMutateAsyncFunction<
461
443
  /**
462
444
  * The result of `useMutation`. Same as {@link MutationObserverResult} from `@tanstack/query-core`, with
463
445
  * `mutate` narrowed to the fire-and-forget {@link UseMutateFunction} signature, plus the added `mutateAsync`.
464
- *
465
446
  * @template TData - The type your mutation function resolves to.
466
447
  * @template TError - The type of errors your mutation function may throw.
467
448
  * @template TVariables - The type of the variable passed to `mutate`/`mutateAsync`.
@@ -490,7 +471,6 @@ export type UseBaseMutationResult<
490
471
 
491
472
  /**
492
473
  * The result of `useMutation`. Same as {@link UseBaseMutationResult}.
493
- *
494
474
  * @template TData - The type your mutation function resolves to.
495
475
  * @template TError - The type of errors your mutation function may throw.
496
476
  * @template TVariables - The type of the variable passed to `mutate`/`mutateAsync`.
@@ -1,10 +1,4 @@
1
1
  import { noop, notifyManager } from '@tanstack/query-core'
2
- import type {
3
- QueryClient,
4
- QueryKey,
5
- QueryObserver,
6
- QueryObserverResult,
7
- } from '@tanstack/query-core'
8
2
  import { useCallback, useEffect, useState } from 'preact/hooks'
9
3
 
10
4
  import { useIsRestoring } from './IsRestoringProvider'
@@ -20,9 +14,28 @@ import {
20
14
  fetchOptimistic,
21
15
  shouldSuspend,
22
16
  } from './suspense'
23
- import type { UseBaseQueryOptions } from './types'
24
17
  import { useSyncExternalStore } from './utils'
18
+ import type { UseBaseQueryOptions } from './types'
19
+ import type {
20
+ QueryClient,
21
+ QueryKey,
22
+ QueryObserver,
23
+ QueryObserverResult,
24
+ } from '@tanstack/query-core'
25
25
 
26
+ /**
27
+ * Base implementation shared by `useQuery`, `useInfiniteQuery`, `useSuspenseQuery`, and
28
+ * `useSuspenseInfiniteQuery`.
29
+ * @param options - The options passed to the calling hook.
30
+ * @param Observer - The observer class from query-core (`QueryObserver` or
31
+ * `InfiniteQueryObserver`).
32
+ * @param queryClient - Use this to use a custom `QueryClient`. Otherwise, the one from the nearest
33
+ * context will be used.
34
+ * @returns The query result, tracking which properties are read unless `notifyOnChangeProps` is
35
+ * set.
36
+ * @throws {Error} If `options` is not an object (outside production), or the query error when it should be
37
+ * thrown to the nearest error boundary (see `throwOnError`). While suspending, it throws a promise instead.
38
+ */
26
39
  export function useBaseQuery<
27
40
  TQueryFnData,
28
41
  TError,
@@ -1,4 +1,5 @@
1
1
  import { InfiniteQueryObserver } from '@tanstack/query-core'
2
+ import { useBaseQuery } from './useBaseQuery'
2
3
  import type {
3
4
  DefaultError,
4
5
  InfiniteData,
@@ -16,18 +17,12 @@ import type {
16
17
  UseInfiniteQueryOptions,
17
18
  UseInfiniteQueryResult,
18
19
  } from './types'
19
- import { useBaseQuery } from './useBaseQuery'
20
20
 
21
21
  /**
22
22
  * The options for `useInfiniteQuery` are identical to `useQuery`, with the addition of
23
23
  * `initialPageParam`, `getNextPageParam`, `getPreviousPageParam`, and `maxPages`.
24
24
  *
25
25
  * This overload is selected when `initialData` is set.
26
- *
27
- * @remarks Keep in mind that imperative fetch calls, such as `fetchNextPage`, may interfere with the default
28
- * refetch behavior, resulting in outdated data. Make sure to call these functions only in response to user
29
- * actions, or add conditions like `hasNextPage && !isFetching`.
30
- * @see {@link infiniteQueryOptions} to share these options between `useInfiniteQuery` and imperative APIs like `queryClient.infiniteQuery`.
31
26
  * @param options - The {@link DefinedInitialDataInfiniteOptions} to use — everything you can pass to `useInfiniteQuery`, with `initialData` set.
32
27
  * @param queryClient - Use this to use a custom `QueryClient`. Otherwise, the one from the nearest context will
33
28
  * be used.
@@ -35,7 +30,10 @@ import { useBaseQuery } from './useBaseQuery'
35
30
  * `hasNextPage`, `hasPreviousPage`, `isFetchingNextPage`, and `isFetchingPreviousPage`. `data.pages` and
36
31
  * `data.pageParams` are also added, as long as a `select` doesn't change `TData` away from its default
37
32
  * `InfiniteData<TQueryFnData>` shape.
38
- *
33
+ * @remarks Keep in mind that imperative fetch calls, such as `fetchNextPage`, may interfere with the default
34
+ * refetch behavior, resulting in outdated data. Make sure to call these functions only in response to user
35
+ * actions, or add conditions like `hasNextPage && !isFetching`.
36
+ * @see {@link infiniteQueryOptions} to share these options between `useInfiniteQuery` and imperative APIs like `queryClient.infiniteQuery`.
39
37
  * @example
40
38
  * ```tsx
41
39
  * import { useInfiniteQuery } from '@tanstack/preact-query'
@@ -82,11 +80,6 @@ export function useInfiniteQuery<
82
80
  /**
83
81
  * The options for `useInfiniteQuery` are identical to `useQuery`, with the addition of
84
82
  * `initialPageParam`, `getNextPageParam`, `getPreviousPageParam`, and `maxPages`.
85
- *
86
- * @remarks Keep in mind that imperative fetch calls, such as `fetchNextPage`, may interfere with the default
87
- * refetch behavior, resulting in outdated data. Make sure to call these functions only in response to user
88
- * actions, or add conditions like `hasNextPage && !isFetching`.
89
- * @see {@link infiniteQueryOptions} to share these options between `useInfiniteQuery` and imperative APIs like `queryClient.infiniteQuery`.
90
83
  * @param options - The {@link UndefinedInitialDataInfiniteOptions} to use — everything you can pass to `useInfiniteQuery`.
91
84
  * @param queryClient - Use this to use a custom `QueryClient`. Otherwise, the one from the nearest context will
92
85
  * be used.
@@ -94,7 +87,10 @@ export function useInfiniteQuery<
94
87
  * `hasNextPage`, `hasPreviousPage`, `isFetchingNextPage`, and `isFetchingPreviousPage`. `data.pages` and
95
88
  * `data.pageParams` are also added, as long as a `select` doesn't change `TData` away from its default
96
89
  * `InfiniteData<TQueryFnData>` shape.
97
- *
90
+ * @remarks Keep in mind that imperative fetch calls, such as `fetchNextPage`, may interfere with the default
91
+ * refetch behavior, resulting in outdated data. Make sure to call these functions only in response to user
92
+ * actions, or add conditions like `hasNextPage && !isFetching`.
93
+ * @see {@link infiniteQueryOptions} to share these options between `useInfiniteQuery` and imperative APIs like `queryClient.infiniteQuery`.
98
94
  * @example
99
95
  * Fetching the next page from a "Load More" button click:
100
96
  * ```tsx
@@ -133,7 +129,6 @@ export function useInfiniteQuery<
133
129
  * )
134
130
  * }
135
131
  * ```
136
- *
137
132
  * @example
138
133
  * Fetching the next page automatically as the user scrolls, using an `IntersectionObserver` on a
139
134
  * sentinel element after the list:
@@ -208,11 +203,6 @@ export function useInfiniteQuery<
208
203
  /**
209
204
  * The options for `useInfiniteQuery` are identical to `useQuery`, with the addition of
210
205
  * `initialPageParam`, `getNextPageParam`, `getPreviousPageParam`, and `maxPages`.
211
- *
212
- * @remarks Keep in mind that imperative fetch calls, such as `fetchNextPage`, may interfere with the default
213
- * refetch behavior, resulting in outdated data. Make sure to call these functions only in response to user
214
- * actions, or add conditions like `hasNextPage && !isFetching`.
215
- * @see {@link infiniteQueryOptions} to share these options between `useInfiniteQuery` and imperative APIs like `queryClient.infiniteQuery`.
216
206
  * @param options - The {@link UseInfiniteQueryOptions} to use — everything you can pass to `useInfiniteQuery`.
217
207
  * @param queryClient - Use this to use a custom `QueryClient`. Otherwise, the one from the nearest context will
218
208
  * be used.
@@ -220,7 +210,10 @@ export function useInfiniteQuery<
220
210
  * `hasNextPage`, `hasPreviousPage`, `isFetchingNextPage`, and `isFetchingPreviousPage`. `data.pages` and
221
211
  * `data.pageParams` are also added, as long as a `select` doesn't change `TData` away from its default
222
212
  * `InfiniteData<TQueryFnData>` shape.
223
- *
213
+ * @remarks Keep in mind that imperative fetch calls, such as `fetchNextPage`, may interfere with the default
214
+ * refetch behavior, resulting in outdated data. Make sure to call these functions only in response to user
215
+ * actions, or add conditions like `hasNextPage && !isFetching`.
216
+ * @see {@link infiniteQueryOptions} to share these options between `useInfiniteQuery` and imperative APIs like `queryClient.infiniteQuery`.
224
217
  * @example
225
218
  * Fetching the next page from a "Load More" button click:
226
219
  * ```tsx
@@ -259,7 +252,6 @@ export function useInfiniteQuery<
259
252
  * )
260
253
  * }
261
254
  * ```
262
- *
263
255
  * @example
264
256
  * Fetching the next page automatically as the user scrolls, using an `IntersectionObserver` on a
265
257
  * sentinel element after the list:
@@ -313,7 +305,6 @@ export function useInfiniteQuery<
313
305
  * )
314
306
  * }
315
307
  * ```
316
- *
317
308
  * @example
318
309
  * A query that's disabled, type safe, until `postId` is set — pass `skipToken` as `queryFn`
319
310
  * instead of setting `enabled: false`:
@@ -1,20 +1,18 @@
1
1
  import { notifyManager } from '@tanstack/query-core'
2
- import type { QueryClient, QueryFilters } from '@tanstack/query-core'
3
2
  import { useCallback } from 'preact/hooks'
4
3
 
5
4
  import { useQueryClient } from './QueryClientProvider'
6
5
  import { useSyncExternalStore } from './utils'
6
+ import type { QueryClient, QueryFilters } from '@tanstack/query-core'
7
7
 
8
8
  /**
9
9
  * The `useIsFetching` hook returns the `number` of the queries that your application is loading or fetching in
10
10
  * the background (useful for app-wide loading indicators).
11
- *
12
11
  * @param filters - The {@link QueryFilters} to narrow down the matched queries.
13
12
  * @param queryClient - Use this to use a custom `QueryClient`. Otherwise, the one from the nearest context will
14
13
  * be used.
15
14
  * @returns Will be the `number` of the queries that your application is currently loading or fetching in the
16
15
  * background.
17
- *
18
16
  * @example
19
17
  * ```tsx
20
18
  * import { useIsFetching } from '@tanstack/preact-query'
@@ -26,7 +24,6 @@ import { useSyncExternalStore } from './utils'
26
24
  * return isFetchingPosts ? <span>Refreshing posts...</span> : null
27
25
  * }
28
26
  * ```
29
- *
30
27
  * @example
31
28
  * A global loading indicator for any query fetching in the background, not just the ones on screen:
32
29
  * ```tsx
@@ -4,25 +4,22 @@ import {
4
4
  notifyManager,
5
5
  shouldThrowError,
6
6
  } from '@tanstack/query-core'
7
- import type { DefaultError, QueryClient } from '@tanstack/query-core'
8
7
  import { useCallback, useEffect, useState } from 'preact/hooks'
9
8
 
10
9
  import { useQueryClient } from './QueryClientProvider'
10
+ import { useSyncExternalStore } from './utils'
11
11
  import type {
12
12
  UseMutateFunction,
13
13
  UseMutationOptions,
14
14
  UseMutationResult,
15
15
  } from './types'
16
- import { useSyncExternalStore } from './utils'
16
+ import type { DefaultError, QueryClient } from '@tanstack/query-core'
17
17
 
18
18
  // HOOK
19
19
 
20
20
  /**
21
21
  * Unlike queries, mutations are typically used to create/update/delete data or perform server side-effects.
22
22
  * `useMutation` is the hook for that.
23
- *
24
- * @see {@link mutationOptions} to share these options across multiple `useMutation` call sites, or to look
25
- * the mutation up elsewhere via its `mutationKey` (e.g. with `useMutationState`).
26
23
  * @param options - The {@link UseMutationOptions} to use — everything you can pass to `useMutation`.
27
24
  * @param queryClient - Use this to use a custom `QueryClient`. Otherwise, the one from the nearest context will
28
25
  * be used.
@@ -31,7 +28,10 @@ import { useSyncExternalStore } from './utils'
31
28
  * mutation definition. Hook-level callbacks (passed to `options`) fire for every mutation; per-call callbacks
32
29
  * fire only for the latest call you've made, and only while the component is still mounted — unmounting before
33
30
  * the mutation settles removes the subscription and prevents them from firing.
34
- *
31
+ * @throws {Error} The mutation error, when `throwOnError` is `true` or returns `true` for it, so that it is
32
+ * thrown to the nearest error boundary.
33
+ * @see {@link mutationOptions} to share these options across multiple `useMutation` call sites, or to look
34
+ * the mutation up elsewhere via its `mutationKey` (e.g. with `useMutationState`).
35
35
  * @example
36
36
  * ```tsx
37
37
  * import { useMutation, useQueryClient } from '@tanstack/preact-query'
@@ -57,7 +57,6 @@ import { useSyncExternalStore } from './utils'
57
57
  * )
58
58
  * }
59
59
  * ```
60
- *
61
60
  * @example
62
61
  * Rendering the mutation's own state, rather than just firing it off:
63
62
  * ```tsx
@@ -87,7 +86,6 @@ import { useSyncExternalStore } from './utils'
87
86
  * )
88
87
  * }
89
88
  * ```
90
- *
91
89
  * @example
92
90
  * Optimistic update via `onMutate`, rolling back on `onError`:
93
91
  * ```tsx
@@ -123,7 +121,6 @@ import { useSyncExternalStore } from './utils'
123
121
  * )
124
122
  * }
125
123
  * ```
126
- *
127
124
  * @example
128
125
  * Callbacks passed per call to `mutate` only fire for the last call — `mutateAsync` gives you a
129
126
  * promise per call instead, so you can wait for all of them when they succeed:
@@ -153,7 +150,6 @@ import { useSyncExternalStore } from './utils'
153
150
  * )
154
151
  * }
155
152
  * ```
156
- *
157
153
  * @example
158
154
  * If some of the mutations above can fail independently of the others, and you want to know which ones
159
155
  * did — rather than losing that information the moment the first one rejects — swap `Promise.all` for
@@ -1,4 +1,8 @@
1
1
  import { notifyManager, replaceEqualDeep } from '@tanstack/query-core'
2
+ import { useCallback, useEffect, useRef } from 'preact/hooks'
3
+
4
+ import { useQueryClient } from './QueryClientProvider'
5
+ import { useSyncExternalStore } from './utils'
2
6
  import type {
3
7
  Mutation,
4
8
  MutationCache,
@@ -6,20 +10,14 @@ import type {
6
10
  MutationState,
7
11
  QueryClient,
8
12
  } from '@tanstack/query-core'
9
- import { useCallback, useEffect, useRef } from 'preact/hooks'
10
-
11
- import { useQueryClient } from './QueryClientProvider'
12
- import { useSyncExternalStore } from './utils'
13
13
 
14
14
  /**
15
15
  * The `useIsMutating` hook returns the `number` of mutations that your application currently has `pending`
16
16
  * (useful for app-wide loading indicators).
17
- *
18
17
  * @param filters - The {@link MutationFilters} to narrow down the matched mutations.
19
18
  * @param queryClient - Use this to use a custom `QueryClient`. Otherwise, the one from the nearest context will
20
19
  * be used.
21
20
  * @returns Will be the `number` of the mutations that your application currently has `pending`.
22
- *
23
21
  * @example
24
22
  * ```tsx
25
23
  * import { useIsMutating } from '@tanstack/preact-query'
@@ -63,6 +61,13 @@ type MutationStateOptions<
63
61
  select?: (mutation: TMutation) => TResult
64
62
  }
65
63
 
64
+ /**
65
+ * Collects the mutations in the cache that match `options.filters`, mapped with `options.select`
66
+ * (or to their state, by default).
67
+ * @param mutationCache - The mutation cache to read.
68
+ * @param options - The `filters` to match and the `select` function to map each mutation with.
69
+ * @returns The selected value of every matching mutation.
70
+ */
66
71
  function getResult<
67
72
  TResult = MutationState,
68
73
  TMutation extends Mutation<any, any, any, any> =
@@ -85,13 +90,11 @@ function getResult<
85
90
  * `useMutationState` is a hook that gives you access to all mutations in the `MutationCache`. You can pass
86
91
  * `filters` ({@link MutationFilters}) to narrow down your mutations, and `select` to transform the mutation
87
92
  * state.
88
- *
89
93
  * @param options - The `filters` to narrow down matched mutations, and an optional `select` to transform the
90
94
  * mutation state.
91
95
  * @param queryClient - Use this to use a custom `QueryClient`. Otherwise, the one from the nearest context will
92
96
  * be used.
93
97
  * @returns Will be an Array of whatever `select` returns for each matching mutation.
94
- *
95
98
  * @example
96
99
  * Get all variables of all running mutations:
97
100
  * ```tsx
@@ -106,7 +109,6 @@ function getResult<
106
109
  * return <>{pendingVariables.length} posts saving...</>
107
110
  * }
108
111
  * ```
109
- *
110
112
  * @example
111
113
  * Get all data for specific mutations via the `mutationKey`:
112
114
  * ```tsx
@@ -134,7 +136,6 @@ function getResult<
134
136
  * )
135
137
  * }
136
138
  * ```
137
- *
138
139
  * @example
139
140
  * Access the latest successful mutation data via the `mutationKey`. Each invocation of `mutate` adds a new
140
141
  * entry to the mutation cache for `gcTime` milliseconds — with the `status: 'success'` filter below, check the
@@ -18,12 +18,9 @@ import type { UsePrefetchInfiniteQueryOptions } from './types'
18
18
  * The prefetch is skipped if the query already has any cached state — including a `pending`/`error` state left
19
19
  * over from a previous attempt — so calling this on every render is cheap and won't refetch data that's
20
20
  * already there or already in flight.
21
- *
22
21
  * @param options - The {@link UsePrefetchInfiniteQueryOptions} to use — everything you can pass to `queryClient.infiniteQuery`.
23
22
  * @param queryClient - Use this to use a custom `QueryClient`. Otherwise, the one from the nearest context will
24
23
  * be used.
25
- * @returns `void` — nothing is returned.
26
- *
27
24
  * @example
28
25
  * ```tsx
29
26
  * import { Suspense } from 'preact/compat'
@@ -13,12 +13,9 @@ import type { UsePrefetchQueryOptions } from './types'
13
13
  * The prefetch is skipped if the query already has any cached state — including a `pending`/`error` state left
14
14
  * over from a previous attempt — so calling this on every render is cheap and won't refetch data that's
15
15
  * already there or already in flight.
16
- *
17
16
  * @param options - The {@link UsePrefetchQueryOptions} to use — everything you can pass to `queryClient.query`.
18
17
  * @param queryClient - Use this to use a custom `QueryClient`. Otherwise, the one from the nearest context will
19
18
  * be used.
20
- * @returns `void` — nothing is returned.
21
- *
22
19
  * @example
23
20
  * ```tsx
24
21
  * import { Suspense } from 'preact/compat'
package/src/useQueries.ts CHANGED
@@ -4,17 +4,6 @@ import {
4
4
  noop,
5
5
  notifyManager,
6
6
  } from '@tanstack/query-core'
7
- import type {
8
- DefaultError,
9
- OmitKeyof,
10
- QueriesObserverOptions,
11
- QueriesPlaceholderDataFunction,
12
- QueryClient,
13
- QueryFunction,
14
- QueryKey,
15
- QueryObserverOptions,
16
- ThrowOnError,
17
- } from '@tanstack/query-core'
18
7
  import { useCallback, useEffect, useMemo, useState } from 'preact/hooks'
19
8
 
20
9
  import { useIsRestoring } from './IsRestoringProvider'
@@ -30,12 +19,23 @@ import {
30
19
  fetchOptimistic,
31
20
  shouldSuspend,
32
21
  } from './suspense'
22
+ import { useSyncExternalStore } from './utils'
33
23
  import type {
34
24
  DefinedUseQueryResult,
35
25
  UseQueryOptions,
36
26
  UseQueryResult,
37
27
  } from './types'
38
- import { useSyncExternalStore } from './utils'
28
+ import type {
29
+ DefaultError,
30
+ OmitKeyof,
31
+ QueriesObserverOptions,
32
+ QueriesPlaceholderDataFunction,
33
+ QueryClient,
34
+ QueryFunction,
35
+ QueryKey,
36
+ QueryObserverOptions,
37
+ ThrowOnError,
38
+ } from '@tanstack/query-core'
39
39
 
40
40
  // This defines the `UseQueryOptions` that are accepted in `QueriesOptions` & `GetOptions`.
41
41
  // `placeholderData` function always gets undefined passed
@@ -150,7 +150,6 @@ type GetUseQueryResult<T> =
150
150
  * matches a query options object is mapped per-element instead, still inferring each entry individually; any
151
151
  * other non-tuple array — one whose element type doesn't match the expected options shape — falls back to
152
152
  * that same homogeneous options type too.
153
- *
154
153
  * @template T - The type of the `queries` array as written at the call site.
155
154
  * @template TResults - The internal accumulator that this type builds during recursion. It is not meant
156
155
  * to be set explicitly.
@@ -201,7 +200,6 @@ export type QueriesOptions<
201
200
  * tuple element's result type is inferred individually, up to 20 elements. A non-tuple array is mapped
202
201
  * per-element instead, still inferring each entry individually; only past 20 elements does this fall back to a
203
202
  * single homogeneous {@link UseQueryResult} type.
204
- *
205
203
  * @template T - The type of the `queries` array, as inferred by {@link QueriesOptions}.
206
204
  * @template TResults - The internal accumulator that this type builds during recursion. It is not meant
207
205
  * to be set explicitly.
@@ -239,12 +237,13 @@ export type QueriesResults<
239
237
  *
240
238
  * The `combine` option can be used to combine the results of the queries into a single value. The result will
241
239
  * be structurally shared to be as referentially stable as possible.
242
- *
240
+ * @param options - The `queries` array to run, and the optional `combine` and `subscribed` options.
243
241
  * @param queryClient - Use this to provide a custom `QueryClient`. Otherwise, the one from the nearest context
244
242
  * will be used.
245
243
  * @returns The combined result. Without `combine`, this is an array with all the query results, in the same
246
244
  * order as the input. When `combine` is provided, this is the value returned by `combine` instead.
247
- *
245
+ * @throws {Error} The error of the first query that should be thrown to the nearest error boundary (see
246
+ * `throwOnError`). While suspending, it throws a promise instead.
248
247
  * @example
249
248
  * ```tsx
250
249
  * import { useQueries } from '@tanstack/preact-query'
@@ -269,7 +268,6 @@ export type QueriesResults<
269
268
  * )
270
269
  * }
271
270
  * ```
272
- *
273
271
  * @example
274
272
  * Combining results into a single value:
275
273
  * ```tsx
@@ -327,7 +325,6 @@ export function useQueries<
327
325
  combine?: (result: QueriesResults<T>) => TCombinedResult
328
326
  /**
329
327
  * Set this to `false` to unsubscribe this observer from updates to the query cache.
330
- *
331
328
  * @defaultValue true
332
329
  */
333
330
  subscribed?: boolean