@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
@@ -7,13 +7,11 @@ let preact_hooks = require("preact/hooks");
7
7
  /**
8
8
  * The `useIsFetching` hook returns the `number` of the queries that your application is loading or fetching in
9
9
  * the background (useful for app-wide loading indicators).
10
- *
11
10
  * @param filters - The {@link QueryFilters} to narrow down the matched queries.
12
11
  * @param queryClient - Use this to use a custom `QueryClient`. Otherwise, the one from the nearest context will
13
12
  * be used.
14
13
  * @returns Will be the `number` of the queries that your application is currently loading or fetching in the
15
14
  * background.
16
- *
17
15
  * @example
18
16
  * ```tsx
19
17
  * import { useIsFetching } from '@tanstack/preact-query'
@@ -25,7 +23,6 @@ let preact_hooks = require("preact/hooks");
25
23
  * return isFetchingPosts ? <span>Refreshing posts...</span> : null
26
24
  * }
27
25
  * ```
28
- *
29
26
  * @example
30
27
  * A global loading indicator for any query fetching in the background, not just the ones on screen:
31
28
  * ```tsx
@@ -1 +1 @@
1
- {"version":3,"file":"useIsFetching.cjs","names":["useQueryClient","useSyncExternalStore","useCallback","notifyManager"],"sources":["../../src/useIsFetching.ts"],"sourcesContent":["import { notifyManager } from '@tanstack/query-core'\nimport type { QueryClient, QueryFilters } from '@tanstack/query-core'\nimport { useCallback } from 'preact/hooks'\n\nimport { useQueryClient } from './QueryClientProvider'\nimport { useSyncExternalStore } from './utils'\n\n/**\n * The `useIsFetching` hook returns the `number` of the queries that your application is loading or fetching in\n * the background (useful for app-wide loading indicators).\n *\n * @param filters - The {@link QueryFilters} to narrow down the matched queries.\n * @param queryClient - Use this to use a custom `QueryClient`. Otherwise, the one from the nearest context will\n * be used.\n * @returns Will be the `number` of the queries that your application is currently loading or fetching in the\n * background.\n *\n * @example\n * ```tsx\n * import { useIsFetching } from '@tanstack/preact-query'\n *\n * function PostsFetchingIndicator() {\n * // How many queries matching the posts prefix are fetching?\n * const isFetchingPosts = useIsFetching({ queryKey: ['posts'] })\n *\n * return isFetchingPosts ? <span>Refreshing posts...</span> : null\n * }\n * ```\n *\n * @example\n * A global loading indicator for any query fetching in the background, not just the ones on screen:\n * ```tsx\n * import { useIsFetching } from '@tanstack/preact-query'\n *\n * function GlobalLoadingIndicator() {\n * const isFetching = useIsFetching()\n *\n * return isFetching ? (\n * <div>Queries are fetching in the background...</div>\n * ) : null\n * }\n * ```\n */\nexport function useIsFetching(\n filters?: QueryFilters,\n queryClient?: QueryClient,\n): number {\n const client = useQueryClient(queryClient)\n const queryCache = client.getQueryCache()\n\n return useSyncExternalStore(\n useCallback(\n (onStoreChange) =>\n queryCache.subscribe(notifyManager.batchCalls(onStoreChange)),\n [queryCache],\n ),\n () => client.isFetching(filters),\n )\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA2CA,SAAgB,cACd,SACA,aACQ;CACR,MAAM,SAASA,4BAAAA,eAAe,WAAW;CACzC,MAAM,aAAa,OAAO,cAAc;CAExC,OAAOC,cAAAA,sBAAAA,GACLC,aAAAA,YAAAA,EACG,kBACC,WAAW,UAAUC,qBAAAA,cAAc,WAAW,aAAa,CAAC,GAC9D,CAAC,UAAU,CACb,SACM,OAAO,WAAW,OAAO,CACjC;AACF"}
1
+ {"version":3,"file":"useIsFetching.cjs","names":["useQueryClient","useSyncExternalStore","useCallback","notifyManager"],"sources":["../../src/useIsFetching.ts"],"sourcesContent":["import { notifyManager } from '@tanstack/query-core'\nimport { useCallback } from 'preact/hooks'\n\nimport { useQueryClient } from './QueryClientProvider'\nimport { useSyncExternalStore } from './utils'\nimport type { QueryClient, QueryFilters } from '@tanstack/query-core'\n\n/**\n * The `useIsFetching` hook returns the `number` of the queries that your application is loading or fetching in\n * the background (useful for app-wide loading indicators).\n * @param filters - The {@link QueryFilters} to narrow down the matched queries.\n * @param queryClient - Use this to use a custom `QueryClient`. Otherwise, the one from the nearest context will\n * be used.\n * @returns Will be the `number` of the queries that your application is currently loading or fetching in the\n * background.\n * @example\n * ```tsx\n * import { useIsFetching } from '@tanstack/preact-query'\n *\n * function PostsFetchingIndicator() {\n * // How many queries matching the posts prefix are fetching?\n * const isFetchingPosts = useIsFetching({ queryKey: ['posts'] })\n *\n * return isFetchingPosts ? <span>Refreshing posts...</span> : null\n * }\n * ```\n * @example\n * A global loading indicator for any query fetching in the background, not just the ones on screen:\n * ```tsx\n * import { useIsFetching } from '@tanstack/preact-query'\n *\n * function GlobalLoadingIndicator() {\n * const isFetching = useIsFetching()\n *\n * return isFetching ? (\n * <div>Queries are fetching in the background...</div>\n * ) : null\n * }\n * ```\n */\nexport function useIsFetching(\n filters?: QueryFilters,\n queryClient?: QueryClient,\n): number {\n const client = useQueryClient(queryClient)\n const queryCache = client.getQueryCache()\n\n return useSyncExternalStore(\n useCallback(\n (onStoreChange) =>\n queryCache.subscribe(notifyManager.batchCalls(onStoreChange)),\n [queryCache],\n ),\n () => client.isFetching(filters),\n )\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAwCA,SAAgB,cACd,SACA,aACQ;CACR,MAAM,SAASA,4BAAAA,eAAe,WAAW;CACzC,MAAM,aAAa,OAAO,cAAc;CAExC,OAAOC,cAAAA,sBAAAA,GACLC,aAAAA,YAAAA,EACG,kBACC,WAAW,UAAUC,qBAAAA,cAAc,WAAW,aAAa,CAAC,GAC9D,CAAC,UAAU,CACb,SACM,OAAO,WAAW,OAAO,CACjC;AACF"}
@@ -3,13 +3,11 @@ import { QueryClient, QueryFilters } from "@tanstack/query-core";
3
3
  /**
4
4
  * The `useIsFetching` hook returns the `number` of the queries that your application is loading or fetching in
5
5
  * the background (useful for app-wide loading indicators).
6
- *
7
6
  * @param filters - The {@link QueryFilters} to narrow down the matched queries.
8
7
  * @param queryClient - Use this to use a custom `QueryClient`. Otherwise, the one from the nearest context will
9
8
  * be used.
10
9
  * @returns Will be the `number` of the queries that your application is currently loading or fetching in the
11
10
  * background.
12
- *
13
11
  * @example
14
12
  * ```tsx
15
13
  * import { useIsFetching } from '@tanstack/preact-query'
@@ -21,7 +19,6 @@ import { QueryClient, QueryFilters } from "@tanstack/query-core";
21
19
  * return isFetchingPosts ? <span>Refreshing posts...</span> : null
22
20
  * }
23
21
  * ```
24
- *
25
22
  * @example
26
23
  * A global loading indicator for any query fetching in the background, not just the ones on screen:
27
24
  * ```tsx
@@ -1 +1 @@
1
- {"version":3,"file":"useIsFetching.d.cts","names":[],"sources":["../../src/useIsFetching.ts"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;wBA2CgB,cACd,UAAU,cACV,cAAc"}
1
+ {"version":3,"file":"useIsFetching.d.cts","names":[],"sources":["../../src/useIsFetching.ts"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;wBAwCgB,cACd,UAAU,cACV,cAAc"}
@@ -3,13 +3,11 @@ import { QueryClient, QueryFilters } from "@tanstack/query-core";
3
3
  /**
4
4
  * The `useIsFetching` hook returns the `number` of the queries that your application is loading or fetching in
5
5
  * the background (useful for app-wide loading indicators).
6
- *
7
6
  * @param filters - The {@link QueryFilters} to narrow down the matched queries.
8
7
  * @param queryClient - Use this to use a custom `QueryClient`. Otherwise, the one from the nearest context will
9
8
  * be used.
10
9
  * @returns Will be the `number` of the queries that your application is currently loading or fetching in the
11
10
  * background.
12
- *
13
11
  * @example
14
12
  * ```tsx
15
13
  * import { useIsFetching } from '@tanstack/preact-query'
@@ -21,7 +19,6 @@ import { QueryClient, QueryFilters } from "@tanstack/query-core";
21
19
  * return isFetchingPosts ? <span>Refreshing posts...</span> : null
22
20
  * }
23
21
  * ```
24
- *
25
22
  * @example
26
23
  * A global loading indicator for any query fetching in the background, not just the ones on screen:
27
24
  * ```tsx
@@ -1 +1 @@
1
- {"version":3,"file":"useIsFetching.d.ts","names":[],"sources":["../../src/useIsFetching.ts"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;wBA2CgB,cACd,UAAU,cACV,cAAc"}
1
+ {"version":3,"file":"useIsFetching.d.ts","names":[],"sources":["../../src/useIsFetching.ts"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;wBAwCgB,cACd,UAAU,cACV,cAAc"}
@@ -6,13 +6,11 @@ import { useCallback } from "preact/hooks";
6
6
  /**
7
7
  * The `useIsFetching` hook returns the `number` of the queries that your application is loading or fetching in
8
8
  * the background (useful for app-wide loading indicators).
9
- *
10
9
  * @param filters - The {@link QueryFilters} to narrow down the matched queries.
11
10
  * @param queryClient - Use this to use a custom `QueryClient`. Otherwise, the one from the nearest context will
12
11
  * be used.
13
12
  * @returns Will be the `number` of the queries that your application is currently loading or fetching in the
14
13
  * background.
15
- *
16
14
  * @example
17
15
  * ```tsx
18
16
  * import { useIsFetching } from '@tanstack/preact-query'
@@ -24,7 +22,6 @@ import { useCallback } from "preact/hooks";
24
22
  * return isFetchingPosts ? <span>Refreshing posts...</span> : null
25
23
  * }
26
24
  * ```
27
- *
28
25
  * @example
29
26
  * A global loading indicator for any query fetching in the background, not just the ones on screen:
30
27
  * ```tsx
@@ -1 +1 @@
1
- {"version":3,"file":"useIsFetching.js","names":[],"sources":["../../src/useIsFetching.ts"],"sourcesContent":["import { notifyManager } from '@tanstack/query-core'\nimport type { QueryClient, QueryFilters } from '@tanstack/query-core'\nimport { useCallback } from 'preact/hooks'\n\nimport { useQueryClient } from './QueryClientProvider'\nimport { useSyncExternalStore } from './utils'\n\n/**\n * The `useIsFetching` hook returns the `number` of the queries that your application is loading or fetching in\n * the background (useful for app-wide loading indicators).\n *\n * @param filters - The {@link QueryFilters} to narrow down the matched queries.\n * @param queryClient - Use this to use a custom `QueryClient`. Otherwise, the one from the nearest context will\n * be used.\n * @returns Will be the `number` of the queries that your application is currently loading or fetching in the\n * background.\n *\n * @example\n * ```tsx\n * import { useIsFetching } from '@tanstack/preact-query'\n *\n * function PostsFetchingIndicator() {\n * // How many queries matching the posts prefix are fetching?\n * const isFetchingPosts = useIsFetching({ queryKey: ['posts'] })\n *\n * return isFetchingPosts ? <span>Refreshing posts...</span> : null\n * }\n * ```\n *\n * @example\n * A global loading indicator for any query fetching in the background, not just the ones on screen:\n * ```tsx\n * import { useIsFetching } from '@tanstack/preact-query'\n *\n * function GlobalLoadingIndicator() {\n * const isFetching = useIsFetching()\n *\n * return isFetching ? (\n * <div>Queries are fetching in the background...</div>\n * ) : null\n * }\n * ```\n */\nexport function useIsFetching(\n filters?: QueryFilters,\n queryClient?: QueryClient,\n): number {\n const client = useQueryClient(queryClient)\n const queryCache = client.getQueryCache()\n\n return useSyncExternalStore(\n useCallback(\n (onStoreChange) =>\n queryCache.subscribe(notifyManager.batchCalls(onStoreChange)),\n [queryCache],\n ),\n () => client.isFetching(filters),\n )\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA2CA,SAAgB,cACd,SACA,aACQ;CACR,MAAM,SAAS,eAAe,WAAW;CACzC,MAAM,aAAa,OAAO,cAAc;CAExC,OAAO,qBACL,aACG,kBACC,WAAW,UAAU,cAAc,WAAW,aAAa,CAAC,GAC9D,CAAC,UAAU,CACb,SACM,OAAO,WAAW,OAAO,CACjC;AACF"}
1
+ {"version":3,"file":"useIsFetching.js","names":[],"sources":["../../src/useIsFetching.ts"],"sourcesContent":["import { notifyManager } from '@tanstack/query-core'\nimport { useCallback } from 'preact/hooks'\n\nimport { useQueryClient } from './QueryClientProvider'\nimport { useSyncExternalStore } from './utils'\nimport type { QueryClient, QueryFilters } from '@tanstack/query-core'\n\n/**\n * The `useIsFetching` hook returns the `number` of the queries that your application is loading or fetching in\n * the background (useful for app-wide loading indicators).\n * @param filters - The {@link QueryFilters} to narrow down the matched queries.\n * @param queryClient - Use this to use a custom `QueryClient`. Otherwise, the one from the nearest context will\n * be used.\n * @returns Will be the `number` of the queries that your application is currently loading or fetching in the\n * background.\n * @example\n * ```tsx\n * import { useIsFetching } from '@tanstack/preact-query'\n *\n * function PostsFetchingIndicator() {\n * // How many queries matching the posts prefix are fetching?\n * const isFetchingPosts = useIsFetching({ queryKey: ['posts'] })\n *\n * return isFetchingPosts ? <span>Refreshing posts...</span> : null\n * }\n * ```\n * @example\n * A global loading indicator for any query fetching in the background, not just the ones on screen:\n * ```tsx\n * import { useIsFetching } from '@tanstack/preact-query'\n *\n * function GlobalLoadingIndicator() {\n * const isFetching = useIsFetching()\n *\n * return isFetching ? (\n * <div>Queries are fetching in the background...</div>\n * ) : null\n * }\n * ```\n */\nexport function useIsFetching(\n filters?: QueryFilters,\n queryClient?: QueryClient,\n): number {\n const client = useQueryClient(queryClient)\n const queryCache = client.getQueryCache()\n\n return useSyncExternalStore(\n useCallback(\n (onStoreChange) =>\n queryCache.subscribe(notifyManager.batchCalls(onStoreChange)),\n [queryCache],\n ),\n () => client.isFetching(filters),\n )\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAwCA,SAAgB,cACd,SACA,aACQ;CACR,MAAM,SAAS,eAAe,WAAW;CACzC,MAAM,aAAa,OAAO,cAAc;CAExC,OAAO,qBACL,aACG,kBACC,WAAW,UAAU,cAAc,WAAW,aAAa,CAAC,GAC9D,CAAC,UAAU,CACb,SACM,OAAO,WAAW,OAAO,CACjC;AACF"}
@@ -7,9 +7,6 @@ let preact_hooks = require("preact/hooks");
7
7
  /**
8
8
  * Unlike queries, mutations are typically used to create/update/delete data or perform server side-effects.
9
9
  * `useMutation` is the hook for that.
10
- *
11
- * @see {@link mutationOptions} to share these options across multiple `useMutation` call sites, or to look
12
- * the mutation up elsewhere via its `mutationKey` (e.g. with `useMutationState`).
13
10
  * @param options - The {@link UseMutationOptions} to use — everything you can pass to `useMutation`.
14
11
  * @param queryClient - Use this to use a custom `QueryClient`. Otherwise, the one from the nearest context will
15
12
  * be used.
@@ -18,7 +15,10 @@ let preact_hooks = require("preact/hooks");
18
15
  * mutation definition. Hook-level callbacks (passed to `options`) fire for every mutation; per-call callbacks
19
16
  * fire only for the latest call you've made, and only while the component is still mounted — unmounting before
20
17
  * the mutation settles removes the subscription and prevents them from firing.
21
- *
18
+ * @throws {Error} The mutation error, when `throwOnError` is `true` or returns `true` for it, so that it is
19
+ * thrown to the nearest error boundary.
20
+ * @see {@link mutationOptions} to share these options across multiple `useMutation` call sites, or to look
21
+ * the mutation up elsewhere via its `mutationKey` (e.g. with `useMutationState`).
22
22
  * @example
23
23
  * ```tsx
24
24
  * import { useMutation, useQueryClient } from '@tanstack/preact-query'
@@ -44,7 +44,6 @@ let preact_hooks = require("preact/hooks");
44
44
  * )
45
45
  * }
46
46
  * ```
47
- *
48
47
  * @example
49
48
  * Rendering the mutation's own state, rather than just firing it off:
50
49
  * ```tsx
@@ -74,7 +73,6 @@ let preact_hooks = require("preact/hooks");
74
73
  * )
75
74
  * }
76
75
  * ```
77
- *
78
76
  * @example
79
77
  * Optimistic update via `onMutate`, rolling back on `onError`:
80
78
  * ```tsx
@@ -110,7 +108,6 @@ let preact_hooks = require("preact/hooks");
110
108
  * )
111
109
  * }
112
110
  * ```
113
- *
114
111
  * @example
115
112
  * Callbacks passed per call to `mutate` only fire for the last call — `mutateAsync` gives you a
116
113
  * promise per call instead, so you can wait for all of them when they succeed:
@@ -140,7 +137,6 @@ let preact_hooks = require("preact/hooks");
140
137
  * )
141
138
  * }
142
139
  * ```
143
- *
144
140
  * @example
145
141
  * If some of the mutations above can fail independently of the others, and you want to know which ones
146
142
  * did — rather than losing that information the moment the first one rejects — swap `Promise.all` for
@@ -1 +1 @@
1
- {"version":3,"file":"useMutation.cjs","names":["useQueryClient","useState","MutationObserver","useSyncExternalStore","useCallback","notifyManager","noop","shouldThrowError"],"sources":["../../src/useMutation.ts"],"sourcesContent":["import {\n MutationObserver,\n noop,\n notifyManager,\n shouldThrowError,\n} from '@tanstack/query-core'\nimport type { DefaultError, QueryClient } from '@tanstack/query-core'\nimport { useCallback, useEffect, useState } from 'preact/hooks'\n\nimport { useQueryClient } from './QueryClientProvider'\nimport type {\n UseMutateFunction,\n UseMutationOptions,\n UseMutationResult,\n} from './types'\nimport { useSyncExternalStore } from './utils'\n\n// HOOK\n\n/**\n * Unlike queries, mutations are typically used to create/update/delete data or perform server side-effects.\n * `useMutation` is the hook for that.\n *\n * @see {@link mutationOptions} to share these options across multiple `useMutation` call sites, or to look\n * the mutation up elsewhere via its `mutationKey` (e.g. with `useMutationState`).\n * @param options - The {@link UseMutationOptions} to use — everything you can pass to `useMutation`.\n * @param queryClient - Use this to use a custom `QueryClient`. Otherwise, the one from the nearest context will\n * be used.\n * @returns `mutate`/`mutateAsync` also accept per-call `onSuccess`/`onError`/`onSettled` callbacks as a second\n * argument, useful for triggering call-site side effects (e.g. navigation) without coupling them to the shared\n * mutation definition. Hook-level callbacks (passed to `options`) fire for every mutation; per-call callbacks\n * fire only for the latest call you've made, and only while the component is still mounted — unmounting before\n * the mutation settles removes the subscription and prevents them from firing.\n *\n * @example\n * ```tsx\n * import { useMutation, useQueryClient } from '@tanstack/preact-query'\n *\n * function AddTodo() {\n * const queryClient = useQueryClient()\n *\n * const addMutation = useMutation({\n * mutationFn: addTodo,\n * onSuccess: () => queryClient.invalidateQueries({ queryKey: ['todos'] }),\n * })\n *\n * return (\n * <button\n * onClick={() =>\n * addMutation.mutate('Item', {\n * onError: (error) => console.error('Failed to add item:', error),\n * })\n * }\n * >\n * Add\n * </button>\n * )\n * }\n * ```\n *\n * @example\n * Rendering the mutation's own state, rather than just firing it off:\n * ```tsx\n * import { useMutation, useQueryClient } from '@tanstack/preact-query'\n *\n * function AddTodo() {\n * const queryClient = useQueryClient()\n *\n * const addMutation = useMutation({\n * mutationFn: addTodo,\n * onSuccess: () => queryClient.invalidateQueries({ queryKey: ['todos'] }),\n * })\n *\n * return (\n * <div>\n * {addMutation.isPending ? (\n * 'Adding todo...'\n * ) : (\n * <>\n * {addMutation.isError ? (\n * <div>An error occurred: {addMutation.error.message}</div>\n * ) : null}\n * <button onClick={() => addMutation.mutate('Item')}>Add</button>\n * </>\n * )}\n * </div>\n * )\n * }\n * ```\n *\n * @example\n * Optimistic update via `onMutate`, rolling back on `onError`:\n * ```tsx\n * import { useMutation, useQueryClient } from '@tanstack/preact-query'\n *\n * function AddTodo() {\n * const queryClient = useQueryClient()\n *\n * const addMutation = useMutation({\n * mutationFn: addTodo,\n * onMutate: async (newTodo) => {\n * await queryClient.cancelQueries({ queryKey: ['todos'] })\n * const previousTodos = queryClient.getQueryData<Array<string>>(['todos'])\n *\n * queryClient.setQueryData<Array<string>>(['todos'], (old) => [\n * ...(old ?? []),\n * newTodo,\n * ])\n *\n * // Passed to `onError` as `onMutateResult` if the mutation fails.\n * return { previousTodos }\n * },\n * onError: (_err, _newTodo, onMutateResult) => {\n * queryClient.setQueryData(['todos'], onMutateResult?.previousTodos)\n * },\n * onSettled: () => {\n * queryClient.invalidateQueries({ queryKey: ['todos'] })\n * },\n * })\n *\n * return (\n * <button onClick={() => addMutation.mutate('Item')}>Add</button>\n * )\n * }\n * ```\n *\n * @example\n * Callbacks passed per call to `mutate` only fire for the last call — `mutateAsync` gives you a\n * promise per call instead, so you can wait for all of them when they succeed:\n * ```tsx\n * import { useMutation, useQueryClient } from '@tanstack/preact-query'\n *\n * function AddTodos() {\n * const queryClient = useQueryClient()\n *\n * const addMutation = useMutation({\n * mutationFn: addTodo,\n * onSuccess: () => queryClient.invalidateQueries({ queryKey: ['todos'] }),\n * })\n *\n * async function handleAddAll(todos: Array<string>) {\n * try {\n * await Promise.all(todos.map((todo) => addMutation.mutateAsync(todo)))\n * } catch (error) {\n * console.error('Failed to add todos:', error)\n * }\n * }\n *\n * return (\n * <button onClick={() => handleAddAll(['Todo 1', 'Todo 2', 'Todo 3'])}>\n * Add all\n * </button>\n * )\n * }\n * ```\n *\n * @example\n * If some of the mutations above can fail independently of the others, and you want to know which ones\n * did — rather than losing that information the moment the first one rejects — swap `Promise.all` for\n * `Promise.allSettled`:\n * ```tsx\n * import { useMutation, useQueryClient } from '@tanstack/preact-query'\n *\n * function AddTodos() {\n * const queryClient = useQueryClient()\n *\n * const addMutation = useMutation({\n * mutationFn: addTodo,\n * onSuccess: () => queryClient.invalidateQueries({ queryKey: ['todos'] }),\n * })\n *\n * async function handleAddAll(todos: Array<string>) {\n * const addResults = await Promise.allSettled(\n * todos.map((todo) => addMutation.mutateAsync(todo)),\n * )\n *\n * addResults.forEach((addResult, index) => {\n * if (addResult.status === 'rejected') {\n * console.error(`Failed to add \"${todos[index]}\":`, addResult.reason)\n * }\n * })\n * }\n *\n * return (\n * <button onClick={() => handleAddAll(['Todo 1', 'Todo 2', 'Todo 3'])}>\n * Add all\n * </button>\n * )\n * }\n * ```\n */\nexport function useMutation<\n TData = unknown,\n TError = DefaultError,\n TVariables = void,\n TOnMutateResult = unknown,\n>(\n options: UseMutationOptions<TData, TError, TVariables, TOnMutateResult>,\n queryClient?: QueryClient,\n): UseMutationResult<TData, TError, TVariables, TOnMutateResult> {\n const client = useQueryClient(queryClient)\n\n const [observer] = useState(\n () =>\n new MutationObserver<TData, TError, TVariables, TOnMutateResult>(\n client,\n options,\n ),\n )\n\n useEffect(() => {\n observer.setOptions(options)\n }, [observer, options])\n\n const result = useSyncExternalStore(\n useCallback(\n (onStoreChange) =>\n observer.subscribe(notifyManager.batchCalls(onStoreChange)),\n [observer],\n ),\n () => observer.getCurrentResult(),\n )\n\n const mutate = useCallback<\n UseMutateFunction<TData, TError, TVariables, TOnMutateResult>\n >(\n (\n ...args: Parameters<\n UseMutateFunction<TData, TError, TVariables, TOnMutateResult>\n >\n ) => {\n observer.mutate(args[0] as TVariables, args[1]).catch(noop)\n },\n [observer],\n )\n\n if (\n result.error &&\n shouldThrowError(observer.options.throwOnError, [result.error])\n ) {\n throw result.error\n }\n\n return { ...result, mutate, mutateAsync: result.mutate }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA+LA,SAAgB,YAMd,SACA,aAC+D;CAC/D,MAAM,SAASA,4BAAAA,eAAe,WAAW;CAEzC,MAAM,CAAC,aAAA,GAAYC,aAAAA,SAAAA,OAEf,IAAIC,qBAAAA,iBACF,QACA,OACF,CACJ;CAEA,CAAA,GAAA,aAAA,UAAA,OAAgB;EACd,SAAS,WAAW,OAAO;CAC7B,GAAG,CAAC,UAAU,OAAO,CAAC;CAEtB,MAAM,SAASC,cAAAA,sBAAAA,GACbC,aAAAA,YAAAA,EACG,kBACC,SAAS,UAAUC,qBAAAA,cAAc,WAAW,aAAa,CAAC,GAC5D,CAAC,QAAQ,CACX,SACM,SAAS,iBAAiB,CAClC;CAEA,MAAM,UAAA,GAASD,aAAAA,YAAAA,EAIX,GAAG,SAGA;EACH,SAAS,OAAO,KAAK,IAAkB,KAAK,EAAE,CAAC,CAAC,MAAME,qBAAAA,IAAI;CAC5D,GACA,CAAC,QAAQ,CACX;CAEA,IACE,OAAO,UAAA,GACPC,qBAAAA,iBAAAA,CAAiB,SAAS,QAAQ,cAAc,CAAC,OAAO,KAAK,CAAC,GAE9D,MAAM,OAAO;CAGf,OAAO;EAAE,GAAG;EAAQ;EAAQ,aAAa,OAAO;CAAO;AACzD"}
1
+ {"version":3,"file":"useMutation.cjs","names":["useQueryClient","useState","MutationObserver","useSyncExternalStore","useCallback","notifyManager","noop","shouldThrowError"],"sources":["../../src/useMutation.ts"],"sourcesContent":["import {\n MutationObserver,\n noop,\n notifyManager,\n shouldThrowError,\n} from '@tanstack/query-core'\nimport { useCallback, useEffect, useState } from 'preact/hooks'\n\nimport { useQueryClient } from './QueryClientProvider'\nimport { useSyncExternalStore } from './utils'\nimport type {\n UseMutateFunction,\n UseMutationOptions,\n UseMutationResult,\n} from './types'\nimport type { DefaultError, QueryClient } from '@tanstack/query-core'\n\n// HOOK\n\n/**\n * Unlike queries, mutations are typically used to create/update/delete data or perform server side-effects.\n * `useMutation` is the hook for that.\n * @param options - The {@link UseMutationOptions} to use — everything you can pass to `useMutation`.\n * @param queryClient - Use this to use a custom `QueryClient`. Otherwise, the one from the nearest context will\n * be used.\n * @returns `mutate`/`mutateAsync` also accept per-call `onSuccess`/`onError`/`onSettled` callbacks as a second\n * argument, useful for triggering call-site side effects (e.g. navigation) without coupling them to the shared\n * mutation definition. Hook-level callbacks (passed to `options`) fire for every mutation; per-call callbacks\n * fire only for the latest call you've made, and only while the component is still mounted — unmounting before\n * the mutation settles removes the subscription and prevents them from firing.\n * @throws {Error} The mutation error, when `throwOnError` is `true` or returns `true` for it, so that it is\n * thrown to the nearest error boundary.\n * @see {@link mutationOptions} to share these options across multiple `useMutation` call sites, or to look\n * the mutation up elsewhere via its `mutationKey` (e.g. with `useMutationState`).\n * @example\n * ```tsx\n * import { useMutation, useQueryClient } from '@tanstack/preact-query'\n *\n * function AddTodo() {\n * const queryClient = useQueryClient()\n *\n * const addMutation = useMutation({\n * mutationFn: addTodo,\n * onSuccess: () => queryClient.invalidateQueries({ queryKey: ['todos'] }),\n * })\n *\n * return (\n * <button\n * onClick={() =>\n * addMutation.mutate('Item', {\n * onError: (error) => console.error('Failed to add item:', error),\n * })\n * }\n * >\n * Add\n * </button>\n * )\n * }\n * ```\n * @example\n * Rendering the mutation's own state, rather than just firing it off:\n * ```tsx\n * import { useMutation, useQueryClient } from '@tanstack/preact-query'\n *\n * function AddTodo() {\n * const queryClient = useQueryClient()\n *\n * const addMutation = useMutation({\n * mutationFn: addTodo,\n * onSuccess: () => queryClient.invalidateQueries({ queryKey: ['todos'] }),\n * })\n *\n * return (\n * <div>\n * {addMutation.isPending ? (\n * 'Adding todo...'\n * ) : (\n * <>\n * {addMutation.isError ? (\n * <div>An error occurred: {addMutation.error.message}</div>\n * ) : null}\n * <button onClick={() => addMutation.mutate('Item')}>Add</button>\n * </>\n * )}\n * </div>\n * )\n * }\n * ```\n * @example\n * Optimistic update via `onMutate`, rolling back on `onError`:\n * ```tsx\n * import { useMutation, useQueryClient } from '@tanstack/preact-query'\n *\n * function AddTodo() {\n * const queryClient = useQueryClient()\n *\n * const addMutation = useMutation({\n * mutationFn: addTodo,\n * onMutate: async (newTodo) => {\n * await queryClient.cancelQueries({ queryKey: ['todos'] })\n * const previousTodos = queryClient.getQueryData<Array<string>>(['todos'])\n *\n * queryClient.setQueryData<Array<string>>(['todos'], (old) => [\n * ...(old ?? []),\n * newTodo,\n * ])\n *\n * // Passed to `onError` as `onMutateResult` if the mutation fails.\n * return { previousTodos }\n * },\n * onError: (_err, _newTodo, onMutateResult) => {\n * queryClient.setQueryData(['todos'], onMutateResult?.previousTodos)\n * },\n * onSettled: () => {\n * queryClient.invalidateQueries({ queryKey: ['todos'] })\n * },\n * })\n *\n * return (\n * <button onClick={() => addMutation.mutate('Item')}>Add</button>\n * )\n * }\n * ```\n * @example\n * Callbacks passed per call to `mutate` only fire for the last call — `mutateAsync` gives you a\n * promise per call instead, so you can wait for all of them when they succeed:\n * ```tsx\n * import { useMutation, useQueryClient } from '@tanstack/preact-query'\n *\n * function AddTodos() {\n * const queryClient = useQueryClient()\n *\n * const addMutation = useMutation({\n * mutationFn: addTodo,\n * onSuccess: () => queryClient.invalidateQueries({ queryKey: ['todos'] }),\n * })\n *\n * async function handleAddAll(todos: Array<string>) {\n * try {\n * await Promise.all(todos.map((todo) => addMutation.mutateAsync(todo)))\n * } catch (error) {\n * console.error('Failed to add todos:', error)\n * }\n * }\n *\n * return (\n * <button onClick={() => handleAddAll(['Todo 1', 'Todo 2', 'Todo 3'])}>\n * Add all\n * </button>\n * )\n * }\n * ```\n * @example\n * If some of the mutations above can fail independently of the others, and you want to know which ones\n * did — rather than losing that information the moment the first one rejects — swap `Promise.all` for\n * `Promise.allSettled`:\n * ```tsx\n * import { useMutation, useQueryClient } from '@tanstack/preact-query'\n *\n * function AddTodos() {\n * const queryClient = useQueryClient()\n *\n * const addMutation = useMutation({\n * mutationFn: addTodo,\n * onSuccess: () => queryClient.invalidateQueries({ queryKey: ['todos'] }),\n * })\n *\n * async function handleAddAll(todos: Array<string>) {\n * const addResults = await Promise.allSettled(\n * todos.map((todo) => addMutation.mutateAsync(todo)),\n * )\n *\n * addResults.forEach((addResult, index) => {\n * if (addResult.status === 'rejected') {\n * console.error(`Failed to add \"${todos[index]}\":`, addResult.reason)\n * }\n * })\n * }\n *\n * return (\n * <button onClick={() => handleAddAll(['Todo 1', 'Todo 2', 'Todo 3'])}>\n * Add all\n * </button>\n * )\n * }\n * ```\n */\nexport function useMutation<\n TData = unknown,\n TError = DefaultError,\n TVariables = void,\n TOnMutateResult = unknown,\n>(\n options: UseMutationOptions<TData, TError, TVariables, TOnMutateResult>,\n queryClient?: QueryClient,\n): UseMutationResult<TData, TError, TVariables, TOnMutateResult> {\n const client = useQueryClient(queryClient)\n\n const [observer] = useState(\n () =>\n new MutationObserver<TData, TError, TVariables, TOnMutateResult>(\n client,\n options,\n ),\n )\n\n useEffect(() => {\n observer.setOptions(options)\n }, [observer, options])\n\n const result = useSyncExternalStore(\n useCallback(\n (onStoreChange) =>\n observer.subscribe(notifyManager.batchCalls(onStoreChange)),\n [observer],\n ),\n () => observer.getCurrentResult(),\n )\n\n const mutate = useCallback<\n UseMutateFunction<TData, TError, TVariables, TOnMutateResult>\n >(\n (\n ...args: Parameters<\n UseMutateFunction<TData, TError, TVariables, TOnMutateResult>\n >\n ) => {\n observer.mutate(args[0] as TVariables, args[1]).catch(noop)\n },\n [observer],\n )\n\n if (\n result.error &&\n shouldThrowError(observer.options.throwOnError, [result.error])\n ) {\n throw result.error\n }\n\n return { ...result, mutate, mutateAsync: result.mutate }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA2LA,SAAgB,YAMd,SACA,aAC+D;CAC/D,MAAM,SAASA,4BAAAA,eAAe,WAAW;CAEzC,MAAM,CAAC,aAAA,GAAYC,aAAAA,SAAAA,OAEf,IAAIC,qBAAAA,iBACF,QACA,OACF,CACJ;CAEA,CAAA,GAAA,aAAA,UAAA,OAAgB;EACd,SAAS,WAAW,OAAO;CAC7B,GAAG,CAAC,UAAU,OAAO,CAAC;CAEtB,MAAM,SAASC,cAAAA,sBAAAA,GACbC,aAAAA,YAAAA,EACG,kBACC,SAAS,UAAUC,qBAAAA,cAAc,WAAW,aAAa,CAAC,GAC5D,CAAC,QAAQ,CACX,SACM,SAAS,iBAAiB,CAClC;CAEA,MAAM,UAAA,GAASD,aAAAA,YAAAA,EAIX,GAAG,SAGA;EACH,SAAS,OAAO,KAAK,IAAkB,KAAK,EAAE,CAAC,CAAC,MAAME,qBAAAA,IAAI;CAC5D,GACA,CAAC,QAAQ,CACX;CAEA,IACE,OAAO,UAAA,GACPC,qBAAAA,iBAAAA,CAAiB,SAAS,QAAQ,cAAc,CAAC,OAAO,KAAK,CAAC,GAE9D,MAAM,OAAO;CAGf,OAAO;EAAE,GAAG;EAAQ;EAAQ,aAAa,OAAO;CAAO;AACzD"}
@@ -4,9 +4,6 @@ import { DefaultError, QueryClient } from "@tanstack/query-core";
4
4
  /**
5
5
  * Unlike queries, mutations are typically used to create/update/delete data or perform server side-effects.
6
6
  * `useMutation` is the hook for that.
7
- *
8
- * @see {@link mutationOptions} to share these options across multiple `useMutation` call sites, or to look
9
- * the mutation up elsewhere via its `mutationKey` (e.g. with `useMutationState`).
10
7
  * @param options - The {@link UseMutationOptions} to use — everything you can pass to `useMutation`.
11
8
  * @param queryClient - Use this to use a custom `QueryClient`. Otherwise, the one from the nearest context will
12
9
  * be used.
@@ -15,7 +12,10 @@ import { DefaultError, QueryClient } from "@tanstack/query-core";
15
12
  * mutation definition. Hook-level callbacks (passed to `options`) fire for every mutation; per-call callbacks
16
13
  * fire only for the latest call you've made, and only while the component is still mounted — unmounting before
17
14
  * the mutation settles removes the subscription and prevents them from firing.
18
- *
15
+ * @throws {Error} The mutation error, when `throwOnError` is `true` or returns `true` for it, so that it is
16
+ * thrown to the nearest error boundary.
17
+ * @see {@link mutationOptions} to share these options across multiple `useMutation` call sites, or to look
18
+ * the mutation up elsewhere via its `mutationKey` (e.g. with `useMutationState`).
19
19
  * @example
20
20
  * ```tsx
21
21
  * import { useMutation, useQueryClient } from '@tanstack/preact-query'
@@ -41,7 +41,6 @@ import { DefaultError, QueryClient } from "@tanstack/query-core";
41
41
  * )
42
42
  * }
43
43
  * ```
44
- *
45
44
  * @example
46
45
  * Rendering the mutation's own state, rather than just firing it off:
47
46
  * ```tsx
@@ -71,7 +70,6 @@ import { DefaultError, QueryClient } from "@tanstack/query-core";
71
70
  * )
72
71
  * }
73
72
  * ```
74
- *
75
73
  * @example
76
74
  * Optimistic update via `onMutate`, rolling back on `onError`:
77
75
  * ```tsx
@@ -107,7 +105,6 @@ import { DefaultError, QueryClient } from "@tanstack/query-core";
107
105
  * )
108
106
  * }
109
107
  * ```
110
- *
111
108
  * @example
112
109
  * Callbacks passed per call to `mutate` only fire for the last call — `mutateAsync` gives you a
113
110
  * promise per call instead, so you can wait for all of them when they succeed:
@@ -137,7 +134,6 @@ import { DefaultError, QueryClient } from "@tanstack/query-core";
137
134
  * )
138
135
  * }
139
136
  * ```
140
- *
141
137
  * @example
142
138
  * If some of the mutations above can fail independently of the others, and you want to know which ones
143
139
  * did — rather than losing that information the moment the first one rejects — swap `Promise.all` for
@@ -1 +1 @@
1
- {"version":3,"file":"useMutation.d.cts","names":[],"sources":["../../src/useMutation.ts"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;wBA+LgB,YACd,iBACA,SAAS,cACT,mBACA,2BAEA,SAAS,mBAAmB,OAAO,QAAQ,YAAY,kBACvD,cAAc,cACb,kBAAkB,OAAO,QAAQ,YAAY"}
1
+ {"version":3,"file":"useMutation.d.cts","names":[],"sources":["../../src/useMutation.ts"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;wBA2LgB,YACd,iBACA,SAAS,cACT,mBACA,2BAEA,SAAS,mBAAmB,OAAO,QAAQ,YAAY,kBACvD,cAAc,cACb,kBAAkB,OAAO,QAAQ,YAAY"}
@@ -4,9 +4,6 @@ import { DefaultError, QueryClient } from "@tanstack/query-core";
4
4
  /**
5
5
  * Unlike queries, mutations are typically used to create/update/delete data or perform server side-effects.
6
6
  * `useMutation` is the hook for that.
7
- *
8
- * @see {@link mutationOptions} to share these options across multiple `useMutation` call sites, or to look
9
- * the mutation up elsewhere via its `mutationKey` (e.g. with `useMutationState`).
10
7
  * @param options - The {@link UseMutationOptions} to use — everything you can pass to `useMutation`.
11
8
  * @param queryClient - Use this to use a custom `QueryClient`. Otherwise, the one from the nearest context will
12
9
  * be used.
@@ -15,7 +12,10 @@ import { DefaultError, QueryClient } from "@tanstack/query-core";
15
12
  * mutation definition. Hook-level callbacks (passed to `options`) fire for every mutation; per-call callbacks
16
13
  * fire only for the latest call you've made, and only while the component is still mounted — unmounting before
17
14
  * the mutation settles removes the subscription and prevents them from firing.
18
- *
15
+ * @throws {Error} The mutation error, when `throwOnError` is `true` or returns `true` for it, so that it is
16
+ * thrown to the nearest error boundary.
17
+ * @see {@link mutationOptions} to share these options across multiple `useMutation` call sites, or to look
18
+ * the mutation up elsewhere via its `mutationKey` (e.g. with `useMutationState`).
19
19
  * @example
20
20
  * ```tsx
21
21
  * import { useMutation, useQueryClient } from '@tanstack/preact-query'
@@ -41,7 +41,6 @@ import { DefaultError, QueryClient } from "@tanstack/query-core";
41
41
  * )
42
42
  * }
43
43
  * ```
44
- *
45
44
  * @example
46
45
  * Rendering the mutation's own state, rather than just firing it off:
47
46
  * ```tsx
@@ -71,7 +70,6 @@ import { DefaultError, QueryClient } from "@tanstack/query-core";
71
70
  * )
72
71
  * }
73
72
  * ```
74
- *
75
73
  * @example
76
74
  * Optimistic update via `onMutate`, rolling back on `onError`:
77
75
  * ```tsx
@@ -107,7 +105,6 @@ import { DefaultError, QueryClient } from "@tanstack/query-core";
107
105
  * )
108
106
  * }
109
107
  * ```
110
- *
111
108
  * @example
112
109
  * Callbacks passed per call to `mutate` only fire for the last call — `mutateAsync` gives you a
113
110
  * promise per call instead, so you can wait for all of them when they succeed:
@@ -137,7 +134,6 @@ import { DefaultError, QueryClient } from "@tanstack/query-core";
137
134
  * )
138
135
  * }
139
136
  * ```
140
- *
141
137
  * @example
142
138
  * If some of the mutations above can fail independently of the others, and you want to know which ones
143
139
  * did — rather than losing that information the moment the first one rejects — swap `Promise.all` for
@@ -1 +1 @@
1
- {"version":3,"file":"useMutation.d.ts","names":[],"sources":["../../src/useMutation.ts"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;wBA+LgB,YACd,iBACA,SAAS,cACT,mBACA,2BAEA,SAAS,mBAAmB,OAAO,QAAQ,YAAY,kBACvD,cAAc,cACb,kBAAkB,OAAO,QAAQ,YAAY"}
1
+ {"version":3,"file":"useMutation.d.ts","names":[],"sources":["../../src/useMutation.ts"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;wBA2LgB,YACd,iBACA,SAAS,cACT,mBACA,2BAEA,SAAS,mBAAmB,OAAO,QAAQ,YAAY,kBACvD,cAAc,cACb,kBAAkB,OAAO,QAAQ,YAAY"}
@@ -6,9 +6,6 @@ import { useCallback, useEffect, useState } from "preact/hooks";
6
6
  /**
7
7
  * Unlike queries, mutations are typically used to create/update/delete data or perform server side-effects.
8
8
  * `useMutation` is the hook for that.
9
- *
10
- * @see {@link mutationOptions} to share these options across multiple `useMutation` call sites, or to look
11
- * the mutation up elsewhere via its `mutationKey` (e.g. with `useMutationState`).
12
9
  * @param options - The {@link UseMutationOptions} to use — everything you can pass to `useMutation`.
13
10
  * @param queryClient - Use this to use a custom `QueryClient`. Otherwise, the one from the nearest context will
14
11
  * be used.
@@ -17,7 +14,10 @@ import { useCallback, useEffect, useState } from "preact/hooks";
17
14
  * mutation definition. Hook-level callbacks (passed to `options`) fire for every mutation; per-call callbacks
18
15
  * fire only for the latest call you've made, and only while the component is still mounted — unmounting before
19
16
  * the mutation settles removes the subscription and prevents them from firing.
20
- *
17
+ * @throws {Error} The mutation error, when `throwOnError` is `true` or returns `true` for it, so that it is
18
+ * thrown to the nearest error boundary.
19
+ * @see {@link mutationOptions} to share these options across multiple `useMutation` call sites, or to look
20
+ * the mutation up elsewhere via its `mutationKey` (e.g. with `useMutationState`).
21
21
  * @example
22
22
  * ```tsx
23
23
  * import { useMutation, useQueryClient } from '@tanstack/preact-query'
@@ -43,7 +43,6 @@ import { useCallback, useEffect, useState } from "preact/hooks";
43
43
  * )
44
44
  * }
45
45
  * ```
46
- *
47
46
  * @example
48
47
  * Rendering the mutation's own state, rather than just firing it off:
49
48
  * ```tsx
@@ -73,7 +72,6 @@ import { useCallback, useEffect, useState } from "preact/hooks";
73
72
  * )
74
73
  * }
75
74
  * ```
76
- *
77
75
  * @example
78
76
  * Optimistic update via `onMutate`, rolling back on `onError`:
79
77
  * ```tsx
@@ -109,7 +107,6 @@ import { useCallback, useEffect, useState } from "preact/hooks";
109
107
  * )
110
108
  * }
111
109
  * ```
112
- *
113
110
  * @example
114
111
  * Callbacks passed per call to `mutate` only fire for the last call — `mutateAsync` gives you a
115
112
  * promise per call instead, so you can wait for all of them when they succeed:
@@ -139,7 +136,6 @@ import { useCallback, useEffect, useState } from "preact/hooks";
139
136
  * )
140
137
  * }
141
138
  * ```
142
- *
143
139
  * @example
144
140
  * If some of the mutations above can fail independently of the others, and you want to know which ones
145
141
  * did — rather than losing that information the moment the first one rejects — swap `Promise.all` for
@@ -1 +1 @@
1
- {"version":3,"file":"useMutation.js","names":[],"sources":["../../src/useMutation.ts"],"sourcesContent":["import {\n MutationObserver,\n noop,\n notifyManager,\n shouldThrowError,\n} from '@tanstack/query-core'\nimport type { DefaultError, QueryClient } from '@tanstack/query-core'\nimport { useCallback, useEffect, useState } from 'preact/hooks'\n\nimport { useQueryClient } from './QueryClientProvider'\nimport type {\n UseMutateFunction,\n UseMutationOptions,\n UseMutationResult,\n} from './types'\nimport { useSyncExternalStore } from './utils'\n\n// HOOK\n\n/**\n * Unlike queries, mutations are typically used to create/update/delete data or perform server side-effects.\n * `useMutation` is the hook for that.\n *\n * @see {@link mutationOptions} to share these options across multiple `useMutation` call sites, or to look\n * the mutation up elsewhere via its `mutationKey` (e.g. with `useMutationState`).\n * @param options - The {@link UseMutationOptions} to use — everything you can pass to `useMutation`.\n * @param queryClient - Use this to use a custom `QueryClient`. Otherwise, the one from the nearest context will\n * be used.\n * @returns `mutate`/`mutateAsync` also accept per-call `onSuccess`/`onError`/`onSettled` callbacks as a second\n * argument, useful for triggering call-site side effects (e.g. navigation) without coupling them to the shared\n * mutation definition. Hook-level callbacks (passed to `options`) fire for every mutation; per-call callbacks\n * fire only for the latest call you've made, and only while the component is still mounted — unmounting before\n * the mutation settles removes the subscription and prevents them from firing.\n *\n * @example\n * ```tsx\n * import { useMutation, useQueryClient } from '@tanstack/preact-query'\n *\n * function AddTodo() {\n * const queryClient = useQueryClient()\n *\n * const addMutation = useMutation({\n * mutationFn: addTodo,\n * onSuccess: () => queryClient.invalidateQueries({ queryKey: ['todos'] }),\n * })\n *\n * return (\n * <button\n * onClick={() =>\n * addMutation.mutate('Item', {\n * onError: (error) => console.error('Failed to add item:', error),\n * })\n * }\n * >\n * Add\n * </button>\n * )\n * }\n * ```\n *\n * @example\n * Rendering the mutation's own state, rather than just firing it off:\n * ```tsx\n * import { useMutation, useQueryClient } from '@tanstack/preact-query'\n *\n * function AddTodo() {\n * const queryClient = useQueryClient()\n *\n * const addMutation = useMutation({\n * mutationFn: addTodo,\n * onSuccess: () => queryClient.invalidateQueries({ queryKey: ['todos'] }),\n * })\n *\n * return (\n * <div>\n * {addMutation.isPending ? (\n * 'Adding todo...'\n * ) : (\n * <>\n * {addMutation.isError ? (\n * <div>An error occurred: {addMutation.error.message}</div>\n * ) : null}\n * <button onClick={() => addMutation.mutate('Item')}>Add</button>\n * </>\n * )}\n * </div>\n * )\n * }\n * ```\n *\n * @example\n * Optimistic update via `onMutate`, rolling back on `onError`:\n * ```tsx\n * import { useMutation, useQueryClient } from '@tanstack/preact-query'\n *\n * function AddTodo() {\n * const queryClient = useQueryClient()\n *\n * const addMutation = useMutation({\n * mutationFn: addTodo,\n * onMutate: async (newTodo) => {\n * await queryClient.cancelQueries({ queryKey: ['todos'] })\n * const previousTodos = queryClient.getQueryData<Array<string>>(['todos'])\n *\n * queryClient.setQueryData<Array<string>>(['todos'], (old) => [\n * ...(old ?? []),\n * newTodo,\n * ])\n *\n * // Passed to `onError` as `onMutateResult` if the mutation fails.\n * return { previousTodos }\n * },\n * onError: (_err, _newTodo, onMutateResult) => {\n * queryClient.setQueryData(['todos'], onMutateResult?.previousTodos)\n * },\n * onSettled: () => {\n * queryClient.invalidateQueries({ queryKey: ['todos'] })\n * },\n * })\n *\n * return (\n * <button onClick={() => addMutation.mutate('Item')}>Add</button>\n * )\n * }\n * ```\n *\n * @example\n * Callbacks passed per call to `mutate` only fire for the last call — `mutateAsync` gives you a\n * promise per call instead, so you can wait for all of them when they succeed:\n * ```tsx\n * import { useMutation, useQueryClient } from '@tanstack/preact-query'\n *\n * function AddTodos() {\n * const queryClient = useQueryClient()\n *\n * const addMutation = useMutation({\n * mutationFn: addTodo,\n * onSuccess: () => queryClient.invalidateQueries({ queryKey: ['todos'] }),\n * })\n *\n * async function handleAddAll(todos: Array<string>) {\n * try {\n * await Promise.all(todos.map((todo) => addMutation.mutateAsync(todo)))\n * } catch (error) {\n * console.error('Failed to add todos:', error)\n * }\n * }\n *\n * return (\n * <button onClick={() => handleAddAll(['Todo 1', 'Todo 2', 'Todo 3'])}>\n * Add all\n * </button>\n * )\n * }\n * ```\n *\n * @example\n * If some of the mutations above can fail independently of the others, and you want to know which ones\n * did — rather than losing that information the moment the first one rejects — swap `Promise.all` for\n * `Promise.allSettled`:\n * ```tsx\n * import { useMutation, useQueryClient } from '@tanstack/preact-query'\n *\n * function AddTodos() {\n * const queryClient = useQueryClient()\n *\n * const addMutation = useMutation({\n * mutationFn: addTodo,\n * onSuccess: () => queryClient.invalidateQueries({ queryKey: ['todos'] }),\n * })\n *\n * async function handleAddAll(todos: Array<string>) {\n * const addResults = await Promise.allSettled(\n * todos.map((todo) => addMutation.mutateAsync(todo)),\n * )\n *\n * addResults.forEach((addResult, index) => {\n * if (addResult.status === 'rejected') {\n * console.error(`Failed to add \"${todos[index]}\":`, addResult.reason)\n * }\n * })\n * }\n *\n * return (\n * <button onClick={() => handleAddAll(['Todo 1', 'Todo 2', 'Todo 3'])}>\n * Add all\n * </button>\n * )\n * }\n * ```\n */\nexport function useMutation<\n TData = unknown,\n TError = DefaultError,\n TVariables = void,\n TOnMutateResult = unknown,\n>(\n options: UseMutationOptions<TData, TError, TVariables, TOnMutateResult>,\n queryClient?: QueryClient,\n): UseMutationResult<TData, TError, TVariables, TOnMutateResult> {\n const client = useQueryClient(queryClient)\n\n const [observer] = useState(\n () =>\n new MutationObserver<TData, TError, TVariables, TOnMutateResult>(\n client,\n options,\n ),\n )\n\n useEffect(() => {\n observer.setOptions(options)\n }, [observer, options])\n\n const result = useSyncExternalStore(\n useCallback(\n (onStoreChange) =>\n observer.subscribe(notifyManager.batchCalls(onStoreChange)),\n [observer],\n ),\n () => observer.getCurrentResult(),\n )\n\n const mutate = useCallback<\n UseMutateFunction<TData, TError, TVariables, TOnMutateResult>\n >(\n (\n ...args: Parameters<\n UseMutateFunction<TData, TError, TVariables, TOnMutateResult>\n >\n ) => {\n observer.mutate(args[0] as TVariables, args[1]).catch(noop)\n },\n [observer],\n )\n\n if (\n result.error &&\n shouldThrowError(observer.options.throwOnError, [result.error])\n ) {\n throw result.error\n }\n\n return { ...result, mutate, mutateAsync: result.mutate }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA+LA,SAAgB,YAMd,SACA,aAC+D;CAC/D,MAAM,SAAS,eAAe,WAAW;CAEzC,MAAM,CAAC,YAAY,eAEf,IAAI,iBACF,QACA,OACF,CACJ;CAEA,gBAAgB;EACd,SAAS,WAAW,OAAO;CAC7B,GAAG,CAAC,UAAU,OAAO,CAAC;CAEtB,MAAM,SAAS,qBACb,aACG,kBACC,SAAS,UAAU,cAAc,WAAW,aAAa,CAAC,GAC5D,CAAC,QAAQ,CACX,SACM,SAAS,iBAAiB,CAClC;CAEA,MAAM,SAAS,aAIX,GAAG,SAGA;EACH,SAAS,OAAO,KAAK,IAAkB,KAAK,EAAE,CAAC,CAAC,MAAM,IAAI;CAC5D,GACA,CAAC,QAAQ,CACX;CAEA,IACE,OAAO,SACP,iBAAiB,SAAS,QAAQ,cAAc,CAAC,OAAO,KAAK,CAAC,GAE9D,MAAM,OAAO;CAGf,OAAO;EAAE,GAAG;EAAQ;EAAQ,aAAa,OAAO;CAAO;AACzD"}
1
+ {"version":3,"file":"useMutation.js","names":[],"sources":["../../src/useMutation.ts"],"sourcesContent":["import {\n MutationObserver,\n noop,\n notifyManager,\n shouldThrowError,\n} from '@tanstack/query-core'\nimport { useCallback, useEffect, useState } from 'preact/hooks'\n\nimport { useQueryClient } from './QueryClientProvider'\nimport { useSyncExternalStore } from './utils'\nimport type {\n UseMutateFunction,\n UseMutationOptions,\n UseMutationResult,\n} from './types'\nimport type { DefaultError, QueryClient } from '@tanstack/query-core'\n\n// HOOK\n\n/**\n * Unlike queries, mutations are typically used to create/update/delete data or perform server side-effects.\n * `useMutation` is the hook for that.\n * @param options - The {@link UseMutationOptions} to use — everything you can pass to `useMutation`.\n * @param queryClient - Use this to use a custom `QueryClient`. Otherwise, the one from the nearest context will\n * be used.\n * @returns `mutate`/`mutateAsync` also accept per-call `onSuccess`/`onError`/`onSettled` callbacks as a second\n * argument, useful for triggering call-site side effects (e.g. navigation) without coupling them to the shared\n * mutation definition. Hook-level callbacks (passed to `options`) fire for every mutation; per-call callbacks\n * fire only for the latest call you've made, and only while the component is still mounted — unmounting before\n * the mutation settles removes the subscription and prevents them from firing.\n * @throws {Error} The mutation error, when `throwOnError` is `true` or returns `true` for it, so that it is\n * thrown to the nearest error boundary.\n * @see {@link mutationOptions} to share these options across multiple `useMutation` call sites, or to look\n * the mutation up elsewhere via its `mutationKey` (e.g. with `useMutationState`).\n * @example\n * ```tsx\n * import { useMutation, useQueryClient } from '@tanstack/preact-query'\n *\n * function AddTodo() {\n * const queryClient = useQueryClient()\n *\n * const addMutation = useMutation({\n * mutationFn: addTodo,\n * onSuccess: () => queryClient.invalidateQueries({ queryKey: ['todos'] }),\n * })\n *\n * return (\n * <button\n * onClick={() =>\n * addMutation.mutate('Item', {\n * onError: (error) => console.error('Failed to add item:', error),\n * })\n * }\n * >\n * Add\n * </button>\n * )\n * }\n * ```\n * @example\n * Rendering the mutation's own state, rather than just firing it off:\n * ```tsx\n * import { useMutation, useQueryClient } from '@tanstack/preact-query'\n *\n * function AddTodo() {\n * const queryClient = useQueryClient()\n *\n * const addMutation = useMutation({\n * mutationFn: addTodo,\n * onSuccess: () => queryClient.invalidateQueries({ queryKey: ['todos'] }),\n * })\n *\n * return (\n * <div>\n * {addMutation.isPending ? (\n * 'Adding todo...'\n * ) : (\n * <>\n * {addMutation.isError ? (\n * <div>An error occurred: {addMutation.error.message}</div>\n * ) : null}\n * <button onClick={() => addMutation.mutate('Item')}>Add</button>\n * </>\n * )}\n * </div>\n * )\n * }\n * ```\n * @example\n * Optimistic update via `onMutate`, rolling back on `onError`:\n * ```tsx\n * import { useMutation, useQueryClient } from '@tanstack/preact-query'\n *\n * function AddTodo() {\n * const queryClient = useQueryClient()\n *\n * const addMutation = useMutation({\n * mutationFn: addTodo,\n * onMutate: async (newTodo) => {\n * await queryClient.cancelQueries({ queryKey: ['todos'] })\n * const previousTodos = queryClient.getQueryData<Array<string>>(['todos'])\n *\n * queryClient.setQueryData<Array<string>>(['todos'], (old) => [\n * ...(old ?? []),\n * newTodo,\n * ])\n *\n * // Passed to `onError` as `onMutateResult` if the mutation fails.\n * return { previousTodos }\n * },\n * onError: (_err, _newTodo, onMutateResult) => {\n * queryClient.setQueryData(['todos'], onMutateResult?.previousTodos)\n * },\n * onSettled: () => {\n * queryClient.invalidateQueries({ queryKey: ['todos'] })\n * },\n * })\n *\n * return (\n * <button onClick={() => addMutation.mutate('Item')}>Add</button>\n * )\n * }\n * ```\n * @example\n * Callbacks passed per call to `mutate` only fire for the last call — `mutateAsync` gives you a\n * promise per call instead, so you can wait for all of them when they succeed:\n * ```tsx\n * import { useMutation, useQueryClient } from '@tanstack/preact-query'\n *\n * function AddTodos() {\n * const queryClient = useQueryClient()\n *\n * const addMutation = useMutation({\n * mutationFn: addTodo,\n * onSuccess: () => queryClient.invalidateQueries({ queryKey: ['todos'] }),\n * })\n *\n * async function handleAddAll(todos: Array<string>) {\n * try {\n * await Promise.all(todos.map((todo) => addMutation.mutateAsync(todo)))\n * } catch (error) {\n * console.error('Failed to add todos:', error)\n * }\n * }\n *\n * return (\n * <button onClick={() => handleAddAll(['Todo 1', 'Todo 2', 'Todo 3'])}>\n * Add all\n * </button>\n * )\n * }\n * ```\n * @example\n * If some of the mutations above can fail independently of the others, and you want to know which ones\n * did — rather than losing that information the moment the first one rejects — swap `Promise.all` for\n * `Promise.allSettled`:\n * ```tsx\n * import { useMutation, useQueryClient } from '@tanstack/preact-query'\n *\n * function AddTodos() {\n * const queryClient = useQueryClient()\n *\n * const addMutation = useMutation({\n * mutationFn: addTodo,\n * onSuccess: () => queryClient.invalidateQueries({ queryKey: ['todos'] }),\n * })\n *\n * async function handleAddAll(todos: Array<string>) {\n * const addResults = await Promise.allSettled(\n * todos.map((todo) => addMutation.mutateAsync(todo)),\n * )\n *\n * addResults.forEach((addResult, index) => {\n * if (addResult.status === 'rejected') {\n * console.error(`Failed to add \"${todos[index]}\":`, addResult.reason)\n * }\n * })\n * }\n *\n * return (\n * <button onClick={() => handleAddAll(['Todo 1', 'Todo 2', 'Todo 3'])}>\n * Add all\n * </button>\n * )\n * }\n * ```\n */\nexport function useMutation<\n TData = unknown,\n TError = DefaultError,\n TVariables = void,\n TOnMutateResult = unknown,\n>(\n options: UseMutationOptions<TData, TError, TVariables, TOnMutateResult>,\n queryClient?: QueryClient,\n): UseMutationResult<TData, TError, TVariables, TOnMutateResult> {\n const client = useQueryClient(queryClient)\n\n const [observer] = useState(\n () =>\n new MutationObserver<TData, TError, TVariables, TOnMutateResult>(\n client,\n options,\n ),\n )\n\n useEffect(() => {\n observer.setOptions(options)\n }, [observer, options])\n\n const result = useSyncExternalStore(\n useCallback(\n (onStoreChange) =>\n observer.subscribe(notifyManager.batchCalls(onStoreChange)),\n [observer],\n ),\n () => observer.getCurrentResult(),\n )\n\n const mutate = useCallback<\n UseMutateFunction<TData, TError, TVariables, TOnMutateResult>\n >(\n (\n ...args: Parameters<\n UseMutateFunction<TData, TError, TVariables, TOnMutateResult>\n >\n ) => {\n observer.mutate(args[0] as TVariables, args[1]).catch(noop)\n },\n [observer],\n )\n\n if (\n result.error &&\n shouldThrowError(observer.options.throwOnError, [result.error])\n ) {\n throw result.error\n }\n\n return { ...result, mutate, mutateAsync: result.mutate }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA2LA,SAAgB,YAMd,SACA,aAC+D;CAC/D,MAAM,SAAS,eAAe,WAAW;CAEzC,MAAM,CAAC,YAAY,eAEf,IAAI,iBACF,QACA,OACF,CACJ;CAEA,gBAAgB;EACd,SAAS,WAAW,OAAO;CAC7B,GAAG,CAAC,UAAU,OAAO,CAAC;CAEtB,MAAM,SAAS,qBACb,aACG,kBACC,SAAS,UAAU,cAAc,WAAW,aAAa,CAAC,GAC5D,CAAC,QAAQ,CACX,SACM,SAAS,iBAAiB,CAClC;CAEA,MAAM,SAAS,aAIX,GAAG,SAGA;EACH,SAAS,OAAO,KAAK,IAAkB,KAAK,EAAE,CAAC,CAAC,MAAM,IAAI;CAC5D,GACA,CAAC,QAAQ,CACX;CAEA,IACE,OAAO,SACP,iBAAiB,SAAS,QAAQ,cAAc,CAAC,OAAO,KAAK,CAAC,GAE9D,MAAM,OAAO;CAGf,OAAO;EAAE,GAAG;EAAQ;EAAQ,aAAa,OAAO;CAAO;AACzD"}
@@ -7,12 +7,10 @@ let preact_hooks = require("preact/hooks");
7
7
  /**
8
8
  * The `useIsMutating` hook returns the `number` of mutations that your application currently has `pending`
9
9
  * (useful for app-wide loading indicators).
10
- *
11
10
  * @param filters - The {@link MutationFilters} to narrow down the matched mutations.
12
11
  * @param queryClient - Use this to use a custom `QueryClient`. Otherwise, the one from the nearest context will
13
12
  * be used.
14
13
  * @returns Will be the `number` of the mutations that your application currently has `pending`.
15
- *
16
14
  * @example
17
15
  * ```tsx
18
16
  * import { useIsMutating } from '@tanstack/preact-query'
@@ -32,6 +30,13 @@ function useIsMutating(filters, queryClient) {
32
30
  status: "pending"
33
31
  } }, client).length;
34
32
  }
33
+ /**
34
+ * Collects the mutations in the cache that match `options.filters`, mapped with `options.select`
35
+ * (or to their state, by default).
36
+ * @param mutationCache - The mutation cache to read.
37
+ * @param options - The `filters` to match and the `select` function to map each mutation with.
38
+ * @returns The selected value of every matching mutation.
39
+ */
35
40
  function getResult(mutationCache, options) {
36
41
  return mutationCache.findAll(options.filters).map((mutation) => options.select ? options.select(mutation) : mutation.state);
37
42
  }
@@ -39,13 +44,11 @@ function getResult(mutationCache, options) {
39
44
  * `useMutationState` is a hook that gives you access to all mutations in the `MutationCache`. You can pass
40
45
  * `filters` ({@link MutationFilters}) to narrow down your mutations, and `select` to transform the mutation
41
46
  * state.
42
- *
43
47
  * @param options - The `filters` to narrow down matched mutations, and an optional `select` to transform the
44
48
  * mutation state.
45
49
  * @param queryClient - Use this to use a custom `QueryClient`. Otherwise, the one from the nearest context will
46
50
  * be used.
47
51
  * @returns Will be an Array of whatever `select` returns for each matching mutation.
48
- *
49
52
  * @example
50
53
  * Get all variables of all running mutations:
51
54
  * ```tsx
@@ -60,7 +63,6 @@ function getResult(mutationCache, options) {
60
63
  * return <>{pendingVariables.length} posts saving...</>
61
64
  * }
62
65
  * ```
63
- *
64
66
  * @example
65
67
  * Get all data for specific mutations via the `mutationKey`:
66
68
  * ```tsx
@@ -88,7 +90,6 @@ function getResult(mutationCache, options) {
88
90
  * )
89
91
  * }
90
92
  * ```
91
- *
92
93
  * @example
93
94
  * Access the latest successful mutation data via the `mutationKey`. Each invocation of `mutate` adds a new
94
95
  * entry to the mutation cache for `gcTime` milliseconds — with the `status: 'success'` filter below, check the
@@ -1 +1 @@
1
- {"version":3,"file":"useMutationState.cjs","names":["useQueryClient","useRef","useSyncExternalStore","useCallback","replaceEqualDeep"],"sources":["../../src/useMutationState.ts"],"sourcesContent":["import { notifyManager, replaceEqualDeep } from '@tanstack/query-core'\nimport type {\n Mutation,\n MutationCache,\n MutationFilters,\n MutationState,\n QueryClient,\n} from '@tanstack/query-core'\nimport { useCallback, useEffect, useRef } from 'preact/hooks'\n\nimport { useQueryClient } from './QueryClientProvider'\nimport { useSyncExternalStore } from './utils'\n\n/**\n * The `useIsMutating` hook returns the `number` of mutations that your application currently has `pending`\n * (useful for app-wide loading indicators).\n *\n * @param filters - The {@link MutationFilters} to narrow down the matched mutations.\n * @param queryClient - Use this to use a custom `QueryClient`. Otherwise, the one from the nearest context will\n * be used.\n * @returns Will be the `number` of the mutations that your application currently has `pending`.\n *\n * @example\n * ```tsx\n * import { useIsMutating } from '@tanstack/preact-query'\n *\n * function PostsMutatingIndicator() {\n * // How many mutations matching the posts prefix are in progress?\n * const isMutatingPosts = useIsMutating({ mutationKey: ['posts'] })\n *\n * return isMutatingPosts ? <span>Saving posts...</span> : null\n * }\n * ```\n */\nexport function useIsMutating(\n filters?: MutationFilters,\n queryClient?: QueryClient,\n): number {\n const client = useQueryClient(queryClient)\n return useMutationState(\n { filters: { ...filters, status: 'pending' } },\n client,\n ).length\n}\n\ntype MutationTypeFromResult<TResult> = [TResult] extends [\n MutationState<\n infer TData,\n infer TError,\n infer TVariables,\n infer TOnMutateResult\n >,\n]\n ? Mutation<TData, TError, TVariables, TOnMutateResult>\n : Mutation\n\ntype MutationStateOptions<\n TResult = MutationState,\n TMutation extends Mutation<any, any, any, any> =\n MutationTypeFromResult<TResult>,\n> = {\n filters?: MutationFilters\n select?: (mutation: TMutation) => TResult\n}\n\nfunction getResult<\n TResult = MutationState,\n TMutation extends Mutation<any, any, any, any> =\n MutationTypeFromResult<TResult>,\n>(\n mutationCache: MutationCache,\n options: MutationStateOptions<TResult, TMutation>,\n): Array<TResult> {\n return mutationCache\n .findAll(options.filters)\n .map(\n (mutation): TResult =>\n (options.select\n ? options.select(mutation as TMutation)\n : mutation.state) as TResult,\n )\n}\n\n/**\n * `useMutationState` is a hook that gives you access to all mutations in the `MutationCache`. You can pass\n * `filters` ({@link MutationFilters}) to narrow down your mutations, and `select` to transform the mutation\n * state.\n *\n * @param options - The `filters` to narrow down matched mutations, and an optional `select` to transform the\n * mutation state.\n * @param queryClient - Use this to use a custom `QueryClient`. Otherwise, the one from the nearest context will\n * be used.\n * @returns Will be an Array of whatever `select` returns for each matching mutation.\n *\n * @example\n * Get all variables of all running mutations:\n * ```tsx\n * import { useMutationState } from '@tanstack/preact-query'\n *\n * function PendingPosts() {\n * const pendingVariables = useMutationState({\n * filters: { status: 'pending' },\n * select: (mutation) => mutation.state.variables,\n * })\n *\n * return <>{pendingVariables.length} posts saving...</>\n * }\n * ```\n *\n * @example\n * Get all data for specific mutations via the `mutationKey`:\n * ```tsx\n * import { useMutation, useMutationState } from '@tanstack/preact-query'\n *\n * const mutationKey = ['posts']\n *\n * function Posts() {\n * // Some mutation that we want to get the state for\n * const mutation = useMutation({\n * mutationKey,\n * mutationFn: createPosts,\n * })\n *\n * const savedPosts = useMutationState({\n * // this mutation key needs to match the mutation key of the given mutation (see above)\n * filters: { mutationKey, status: 'success' },\n * select: (mutation) => mutation.state.data,\n * })\n *\n * return (\n * <button onClick={() => mutation.mutate(['New Post'])}>\n * Create post ({savedPosts.length} saved so far)\n * </button>\n * )\n * }\n * ```\n *\n * @example\n * Access the latest successful mutation data via the `mutationKey`. Each invocation of `mutate` adds a new\n * entry to the mutation cache for `gcTime` milliseconds — with the `status: 'success'` filter below, check the\n * last item that `useMutationState` returns to get the latest successful invocation:\n * ```tsx\n * import { useMutationState } from '@tanstack/preact-query'\n *\n * function LatestPost() {\n * const savedPosts = useMutationState({\n * filters: { mutationKey: ['posts'], status: 'success' },\n * select: (mutation) => mutation.state.data,\n * })\n *\n * const latestSavedPost = savedPosts[savedPosts.length - 1]\n *\n * return <>{latestSavedPost ? 'Saved' : 'Nothing saved yet'}</>\n * }\n * ```\n */\nexport function useMutationState<\n TResult = MutationState,\n TMutation extends Mutation<any, any, any, any> =\n MutationTypeFromResult<TResult>,\n>(\n options: MutationStateOptions<TResult, TMutation> = {},\n queryClient?: QueryClient,\n): Array<TResult> {\n const mutationCache = useQueryClient(queryClient).getMutationCache()\n const optionsRef = useRef(options)\n const resultRef = useRef<Array<TResult>>(null)\n if (resultRef.current === null) {\n resultRef.current = getResult(mutationCache, options)\n }\n\n useEffect(() => {\n optionsRef.current = options\n })\n\n return useSyncExternalStore(\n useCallback(\n (onStoreChange) =>\n mutationCache.subscribe(() => {\n const nextResult = replaceEqualDeep(\n resultRef.current,\n getResult(mutationCache, optionsRef.current),\n )\n if (resultRef.current !== nextResult) {\n resultRef.current = nextResult\n notifyManager.schedule(onStoreChange)\n }\n }),\n [mutationCache],\n ),\n () => resultRef.current,\n )!\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;AAkCA,SAAgB,cACd,SACA,aACQ;CACR,MAAM,SAASA,4BAAAA,eAAe,WAAW;CACzC,OAAO,iBACL,EAAE,SAAS;EAAE,GAAG;EAAS,QAAQ;CAAU,EAAE,GAC7C,MACF,CAAC,CAAC;AACJ;AAsBA,SAAS,UAKP,eACA,SACgB;CAChB,OAAO,cACJ,QAAQ,QAAQ,OAAO,CAAC,CACxB,KACE,aACE,QAAQ,SACL,QAAQ,OAAO,QAAqB,IACpC,SAAS,KACjB;AACJ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA2EA,SAAgB,iBAKd,UAAoD,CAAC,GACrD,aACgB;CAChB,MAAM,gBAAgBA,4BAAAA,eAAe,WAAW,CAAC,CAAC,iBAAiB;CACnE,MAAM,cAAA,GAAaC,aAAAA,OAAAA,CAAO,OAAO;CACjC,MAAM,aAAA,GAAYA,aAAAA,OAAAA,CAAuB,IAAI;CAC7C,IAAI,UAAU,YAAY,MACxB,UAAU,UAAU,UAAU,eAAe,OAAO;CAGtD,CAAA,GAAA,aAAA,UAAA,OAAgB;EACd,WAAW,UAAU;CACvB,CAAC;CAED,OAAOC,cAAAA,sBAAAA,GACLC,aAAAA,YAAAA,EACG,kBACC,cAAc,gBAAgB;EAC5B,MAAM,cAAA,GAAaC,qBAAAA,iBAAAA,CACjB,UAAU,SACV,UAAU,eAAe,WAAW,OAAO,CAC7C;EACA,IAAI,UAAU,YAAY,YAAY;GACpC,UAAU,UAAU;GACpB,qBAAA,cAAc,SAAS,aAAa;EACtC;CACF,CAAC,GACH,CAAC,aAAa,CAChB,SACM,UAAU,OAClB;AACF"}
1
+ {"version":3,"file":"useMutationState.cjs","names":["useQueryClient","useRef","useSyncExternalStore","useCallback","replaceEqualDeep"],"sources":["../../src/useMutationState.ts"],"sourcesContent":["import { notifyManager, replaceEqualDeep } from '@tanstack/query-core'\nimport { useCallback, useEffect, useRef } from 'preact/hooks'\n\nimport { useQueryClient } from './QueryClientProvider'\nimport { useSyncExternalStore } from './utils'\nimport type {\n Mutation,\n MutationCache,\n MutationFilters,\n MutationState,\n QueryClient,\n} from '@tanstack/query-core'\n\n/**\n * The `useIsMutating` hook returns the `number` of mutations that your application currently has `pending`\n * (useful for app-wide loading indicators).\n * @param filters - The {@link MutationFilters} to narrow down the matched mutations.\n * @param queryClient - Use this to use a custom `QueryClient`. Otherwise, the one from the nearest context will\n * be used.\n * @returns Will be the `number` of the mutations that your application currently has `pending`.\n * @example\n * ```tsx\n * import { useIsMutating } from '@tanstack/preact-query'\n *\n * function PostsMutatingIndicator() {\n * // How many mutations matching the posts prefix are in progress?\n * const isMutatingPosts = useIsMutating({ mutationKey: ['posts'] })\n *\n * return isMutatingPosts ? <span>Saving posts...</span> : null\n * }\n * ```\n */\nexport function useIsMutating(\n filters?: MutationFilters,\n queryClient?: QueryClient,\n): number {\n const client = useQueryClient(queryClient)\n return useMutationState(\n { filters: { ...filters, status: 'pending' } },\n client,\n ).length\n}\n\ntype MutationTypeFromResult<TResult> = [TResult] extends [\n MutationState<\n infer TData,\n infer TError,\n infer TVariables,\n infer TOnMutateResult\n >,\n]\n ? Mutation<TData, TError, TVariables, TOnMutateResult>\n : Mutation\n\ntype MutationStateOptions<\n TResult = MutationState,\n TMutation extends Mutation<any, any, any, any> =\n MutationTypeFromResult<TResult>,\n> = {\n filters?: MutationFilters\n select?: (mutation: TMutation) => TResult\n}\n\n/**\n * Collects the mutations in the cache that match `options.filters`, mapped with `options.select`\n * (or to their state, by default).\n * @param mutationCache - The mutation cache to read.\n * @param options - The `filters` to match and the `select` function to map each mutation with.\n * @returns The selected value of every matching mutation.\n */\nfunction getResult<\n TResult = MutationState,\n TMutation extends Mutation<any, any, any, any> =\n MutationTypeFromResult<TResult>,\n>(\n mutationCache: MutationCache,\n options: MutationStateOptions<TResult, TMutation>,\n): Array<TResult> {\n return mutationCache\n .findAll(options.filters)\n .map(\n (mutation): TResult =>\n (options.select\n ? options.select(mutation as TMutation)\n : mutation.state) as TResult,\n )\n}\n\n/**\n * `useMutationState` is a hook that gives you access to all mutations in the `MutationCache`. You can pass\n * `filters` ({@link MutationFilters}) to narrow down your mutations, and `select` to transform the mutation\n * state.\n * @param options - The `filters` to narrow down matched mutations, and an optional `select` to transform the\n * mutation state.\n * @param queryClient - Use this to use a custom `QueryClient`. Otherwise, the one from the nearest context will\n * be used.\n * @returns Will be an Array of whatever `select` returns for each matching mutation.\n * @example\n * Get all variables of all running mutations:\n * ```tsx\n * import { useMutationState } from '@tanstack/preact-query'\n *\n * function PendingPosts() {\n * const pendingVariables = useMutationState({\n * filters: { status: 'pending' },\n * select: (mutation) => mutation.state.variables,\n * })\n *\n * return <>{pendingVariables.length} posts saving...</>\n * }\n * ```\n * @example\n * Get all data for specific mutations via the `mutationKey`:\n * ```tsx\n * import { useMutation, useMutationState } from '@tanstack/preact-query'\n *\n * const mutationKey = ['posts']\n *\n * function Posts() {\n * // Some mutation that we want to get the state for\n * const mutation = useMutation({\n * mutationKey,\n * mutationFn: createPosts,\n * })\n *\n * const savedPosts = useMutationState({\n * // this mutation key needs to match the mutation key of the given mutation (see above)\n * filters: { mutationKey, status: 'success' },\n * select: (mutation) => mutation.state.data,\n * })\n *\n * return (\n * <button onClick={() => mutation.mutate(['New Post'])}>\n * Create post ({savedPosts.length} saved so far)\n * </button>\n * )\n * }\n * ```\n * @example\n * Access the latest successful mutation data via the `mutationKey`. Each invocation of `mutate` adds a new\n * entry to the mutation cache for `gcTime` milliseconds — with the `status: 'success'` filter below, check the\n * last item that `useMutationState` returns to get the latest successful invocation:\n * ```tsx\n * import { useMutationState } from '@tanstack/preact-query'\n *\n * function LatestPost() {\n * const savedPosts = useMutationState({\n * filters: { mutationKey: ['posts'], status: 'success' },\n * select: (mutation) => mutation.state.data,\n * })\n *\n * const latestSavedPost = savedPosts[savedPosts.length - 1]\n *\n * return <>{latestSavedPost ? 'Saved' : 'Nothing saved yet'}</>\n * }\n * ```\n */\nexport function useMutationState<\n TResult = MutationState,\n TMutation extends Mutation<any, any, any, any> =\n MutationTypeFromResult<TResult>,\n>(\n options: MutationStateOptions<TResult, TMutation> = {},\n queryClient?: QueryClient,\n): Array<TResult> {\n const mutationCache = useQueryClient(queryClient).getMutationCache()\n const optionsRef = useRef(options)\n const resultRef = useRef<Array<TResult>>(null)\n if (resultRef.current === null) {\n resultRef.current = getResult(mutationCache, options)\n }\n\n useEffect(() => {\n optionsRef.current = options\n })\n\n return useSyncExternalStore(\n useCallback(\n (onStoreChange) =>\n mutationCache.subscribe(() => {\n const nextResult = replaceEqualDeep(\n resultRef.current,\n getResult(mutationCache, optionsRef.current),\n )\n if (resultRef.current !== nextResult) {\n resultRef.current = nextResult\n notifyManager.schedule(onStoreChange)\n }\n }),\n [mutationCache],\n ),\n () => resultRef.current,\n )!\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;AAgCA,SAAgB,cACd,SACA,aACQ;CACR,MAAM,SAASA,4BAAAA,eAAe,WAAW;CACzC,OAAO,iBACL,EAAE,SAAS;EAAE,GAAG;EAAS,QAAQ;CAAU,EAAE,GAC7C,MACF,CAAC,CAAC;AACJ;;;;;;;;AA6BA,SAAS,UAKP,eACA,SACgB;CAChB,OAAO,cACJ,QAAQ,QAAQ,OAAO,CAAC,CACxB,KACE,aACE,QAAQ,SACL,QAAQ,OAAO,QAAqB,IACpC,SAAS,KACjB;AACJ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAuEA,SAAgB,iBAKd,UAAoD,CAAC,GACrD,aACgB;CAChB,MAAM,gBAAgBA,4BAAAA,eAAe,WAAW,CAAC,CAAC,iBAAiB;CACnE,MAAM,cAAA,GAAaC,aAAAA,OAAAA,CAAO,OAAO;CACjC,MAAM,aAAA,GAAYA,aAAAA,OAAAA,CAAuB,IAAI;CAC7C,IAAI,UAAU,YAAY,MACxB,UAAU,UAAU,UAAU,eAAe,OAAO;CAGtD,CAAA,GAAA,aAAA,UAAA,OAAgB;EACd,WAAW,UAAU;CACvB,CAAC;CAED,OAAOC,cAAAA,sBAAAA,GACLC,aAAAA,YAAAA,EACG,kBACC,cAAc,gBAAgB;EAC5B,MAAM,cAAA,GAAaC,qBAAAA,iBAAAA,CACjB,UAAU,SACV,UAAU,eAAe,WAAW,OAAO,CAC7C;EACA,IAAI,UAAU,YAAY,YAAY;GACpC,UAAU,UAAU;GACpB,qBAAA,cAAc,SAAS,aAAa;EACtC;CACF,CAAC,GACH,CAAC,aAAa,CAChB,SACM,UAAU,OAClB;AACF"}
@@ -3,12 +3,10 @@ import { Mutation, MutationFilters, MutationState, QueryClient } from "@tanstack
3
3
  /**
4
4
  * The `useIsMutating` hook returns the `number` of mutations that your application currently has `pending`
5
5
  * (useful for app-wide loading indicators).
6
- *
7
6
  * @param filters - The {@link MutationFilters} to narrow down the matched mutations.
8
7
  * @param queryClient - Use this to use a custom `QueryClient`. Otherwise, the one from the nearest context will
9
8
  * be used.
10
9
  * @returns Will be the `number` of the mutations that your application currently has `pending`.
11
- *
12
10
  * @example
13
11
  * ```tsx
14
12
  * import { useIsMutating } from '@tanstack/preact-query'
@@ -31,13 +29,11 @@ type MutationStateOptions<TResult = MutationState, TMutation extends Mutation<an
31
29
  * `useMutationState` is a hook that gives you access to all mutations in the `MutationCache`. You can pass
32
30
  * `filters` ({@link MutationFilters}) to narrow down your mutations, and `select` to transform the mutation
33
31
  * state.
34
- *
35
32
  * @param options - The `filters` to narrow down matched mutations, and an optional `select` to transform the
36
33
  * mutation state.
37
34
  * @param queryClient - Use this to use a custom `QueryClient`. Otherwise, the one from the nearest context will
38
35
  * be used.
39
36
  * @returns Will be an Array of whatever `select` returns for each matching mutation.
40
- *
41
37
  * @example
42
38
  * Get all variables of all running mutations:
43
39
  * ```tsx
@@ -52,7 +48,6 @@ type MutationStateOptions<TResult = MutationState, TMutation extends Mutation<an
52
48
  * return <>{pendingVariables.length} posts saving...</>
53
49
  * }
54
50
  * ```
55
- *
56
51
  * @example
57
52
  * Get all data for specific mutations via the `mutationKey`:
58
53
  * ```tsx
@@ -80,7 +75,6 @@ type MutationStateOptions<TResult = MutationState, TMutation extends Mutation<an
80
75
  * )
81
76
  * }
82
77
  * ```
83
- *
84
78
  * @example
85
79
  * Access the latest successful mutation data via the `mutationKey`. Each invocation of `mutate` adds a new
86
80
  * entry to the mutation cache for `gcTime` milliseconds — with the `status: 'success'` filter below, check the
@@ -1 +1 @@
1
- {"version":3,"file":"useMutationState.d.cts","names":[],"sources":["../../src/useMutationState.ts"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;wBAkCgB,cACd,UAAU,iBACV,cAAc;KASX,uBAAuB,YAAY,kBACtC,oBACQ,aACA,cACA,kBACA,oBAGN,SAAS,OAAO,QAAQ,YAAY,mBACpC;KAEC,qBACH,UAAU,eACV,kBAAkB,+BAChB,uBAAuB;EAEzB,UAAU;EACV,UAAU,UAAU,cAAc;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;wBA8FpB,iBACd,UAAU,eACV,kBAAkB,+BAChB,uBAAuB,UAEzB,UAAS,qBAAqB,SAAS,YACvC,cAAc,cACb,MAAM"}
1
+ {"version":3,"file":"useMutationState.d.cts","names":[],"sources":["../../src/useMutationState.ts"],"mappings":";;;;;;;;;;;;;;;;;;;;;wBAgCgB,cACd,UAAU,iBACV,cAAc;KASX,uBAAuB,YAAY,kBACtC,oBACQ,aACA,cACA,kBACA,oBAGN,SAAS,OAAO,QAAQ,YAAY,mBACpC;KAEC,qBACH,UAAU,eACV,kBAAkB,+BAChB,uBAAuB;EAEzB,UAAU;EACV,UAAU,UAAU,cAAc;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;wBAiGpB,iBACd,UAAU,eACV,kBAAkB,+BAChB,uBAAuB,UAEzB,UAAS,qBAAqB,SAAS,YACvC,cAAc,cACb,MAAM"}
@@ -3,12 +3,10 @@ import { Mutation, MutationFilters, MutationState, QueryClient } from "@tanstack
3
3
  /**
4
4
  * The `useIsMutating` hook returns the `number` of mutations that your application currently has `pending`
5
5
  * (useful for app-wide loading indicators).
6
- *
7
6
  * @param filters - The {@link MutationFilters} to narrow down the matched mutations.
8
7
  * @param queryClient - Use this to use a custom `QueryClient`. Otherwise, the one from the nearest context will
9
8
  * be used.
10
9
  * @returns Will be the `number` of the mutations that your application currently has `pending`.
11
- *
12
10
  * @example
13
11
  * ```tsx
14
12
  * import { useIsMutating } from '@tanstack/preact-query'
@@ -31,13 +29,11 @@ type MutationStateOptions<TResult = MutationState, TMutation extends Mutation<an
31
29
  * `useMutationState` is a hook that gives you access to all mutations in the `MutationCache`. You can pass
32
30
  * `filters` ({@link MutationFilters}) to narrow down your mutations, and `select` to transform the mutation
33
31
  * state.
34
- *
35
32
  * @param options - The `filters` to narrow down matched mutations, and an optional `select` to transform the
36
33
  * mutation state.
37
34
  * @param queryClient - Use this to use a custom `QueryClient`. Otherwise, the one from the nearest context will
38
35
  * be used.
39
36
  * @returns Will be an Array of whatever `select` returns for each matching mutation.
40
- *
41
37
  * @example
42
38
  * Get all variables of all running mutations:
43
39
  * ```tsx
@@ -52,7 +48,6 @@ type MutationStateOptions<TResult = MutationState, TMutation extends Mutation<an
52
48
  * return <>{pendingVariables.length} posts saving...</>
53
49
  * }
54
50
  * ```
55
- *
56
51
  * @example
57
52
  * Get all data for specific mutations via the `mutationKey`:
58
53
  * ```tsx
@@ -80,7 +75,6 @@ type MutationStateOptions<TResult = MutationState, TMutation extends Mutation<an
80
75
  * )
81
76
  * }
82
77
  * ```
83
- *
84
78
  * @example
85
79
  * Access the latest successful mutation data via the `mutationKey`. Each invocation of `mutate` adds a new
86
80
  * entry to the mutation cache for `gcTime` milliseconds — with the `status: 'success'` filter below, check the