@tanstack/react-query 5.102.8 → 5.103.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (298) hide show
  1. package/build/legacy/HydrationBoundary.cjs +44 -1
  2. package/build/legacy/HydrationBoundary.cjs.map +1 -1
  3. package/build/legacy/HydrationBoundary.d.cts +61 -0
  4. package/build/legacy/HydrationBoundary.d.cts.map +1 -1
  5. package/build/legacy/HydrationBoundary.d.ts +61 -0
  6. package/build/legacy/HydrationBoundary.d.ts.map +1 -1
  7. package/build/legacy/HydrationBoundary.js +44 -1
  8. package/build/legacy/HydrationBoundary.js.map +1 -1
  9. package/build/legacy/IsRestoringProvider.cjs +11 -0
  10. package/build/legacy/IsRestoringProvider.cjs.map +1 -1
  11. package/build/legacy/IsRestoringProvider.d.cts +11 -0
  12. package/build/legacy/IsRestoringProvider.d.cts.map +1 -1
  13. package/build/legacy/IsRestoringProvider.d.ts +11 -0
  14. package/build/legacy/IsRestoringProvider.d.ts.map +1 -1
  15. package/build/legacy/IsRestoringProvider.js +11 -0
  16. package/build/legacy/IsRestoringProvider.js.map +1 -1
  17. package/build/legacy/QueryClientProvider.cjs +30 -0
  18. package/build/legacy/QueryClientProvider.cjs.map +1 -1
  19. package/build/legacy/QueryClientProvider.d.cts +41 -0
  20. package/build/legacy/QueryClientProvider.d.cts.map +1 -1
  21. package/build/legacy/QueryClientProvider.d.ts +41 -0
  22. package/build/legacy/QueryClientProvider.d.ts.map +1 -1
  23. package/build/legacy/QueryClientProvider.js +30 -0
  24. package/build/legacy/QueryClientProvider.js.map +1 -1
  25. package/build/legacy/QueryErrorResetBoundary.cjs +76 -0
  26. package/build/legacy/QueryErrorResetBoundary.cjs.map +1 -1
  27. package/build/legacy/QueryErrorResetBoundary.d.cts +77 -0
  28. package/build/legacy/QueryErrorResetBoundary.d.cts.map +1 -1
  29. package/build/legacy/QueryErrorResetBoundary.d.ts +77 -0
  30. package/build/legacy/QueryErrorResetBoundary.d.ts.map +1 -1
  31. package/build/legacy/QueryErrorResetBoundary.js +76 -0
  32. package/build/legacy/QueryErrorResetBoundary.js.map +1 -1
  33. package/build/legacy/infiniteQueryOptions.cjs.map +1 -1
  34. package/build/legacy/infiniteQueryOptions.d.cts +173 -0
  35. package/build/legacy/infiniteQueryOptions.d.cts.map +1 -1
  36. package/build/legacy/infiniteQueryOptions.d.ts +173 -0
  37. package/build/legacy/infiniteQueryOptions.d.ts.map +1 -1
  38. package/build/legacy/infiniteQueryOptions.js.map +1 -1
  39. package/build/legacy/mutationOptions.cjs.map +1 -1
  40. package/build/legacy/mutationOptions.d.cts +55 -0
  41. package/build/legacy/mutationOptions.d.cts.map +1 -1
  42. package/build/legacy/mutationOptions.d.ts +55 -0
  43. package/build/legacy/mutationOptions.d.ts.map +1 -1
  44. package/build/legacy/mutationOptions.js.map +1 -1
  45. package/build/legacy/queryOptions.cjs.map +1 -1
  46. package/build/legacy/queryOptions.d.cts +175 -0
  47. package/build/legacy/queryOptions.d.cts.map +1 -1
  48. package/build/legacy/queryOptions.d.ts +175 -0
  49. package/build/legacy/queryOptions.d.ts.map +1 -1
  50. package/build/legacy/queryOptions.js.map +1 -1
  51. package/build/legacy/types.cjs.map +1 -1
  52. package/build/legacy/types.d.cts +228 -2
  53. package/build/legacy/types.d.cts.map +1 -1
  54. package/build/legacy/types.d.ts +228 -2
  55. package/build/legacy/types.d.ts.map +1 -1
  56. package/build/legacy/types.js.map +1 -1
  57. package/build/legacy/useInfiniteQuery.cjs.map +1 -1
  58. package/build/legacy/useInfiniteQuery.d.cts +292 -0
  59. package/build/legacy/useInfiniteQuery.d.cts.map +1 -1
  60. package/build/legacy/useInfiniteQuery.d.ts +292 -0
  61. package/build/legacy/useInfiniteQuery.d.ts.map +1 -1
  62. package/build/legacy/useInfiniteQuery.js.map +1 -1
  63. package/build/legacy/useIsFetching.cjs +36 -0
  64. package/build/legacy/useIsFetching.cjs.map +1 -1
  65. package/build/legacy/useIsFetching.d.cts +36 -0
  66. package/build/legacy/useIsFetching.d.cts.map +1 -1
  67. package/build/legacy/useIsFetching.d.ts +36 -0
  68. package/build/legacy/useIsFetching.d.ts.map +1 -1
  69. package/build/legacy/useIsFetching.js +36 -0
  70. package/build/legacy/useIsFetching.js.map +1 -1
  71. package/build/legacy/useMutation.cjs +172 -0
  72. package/build/legacy/useMutation.cjs.map +1 -1
  73. package/build/legacy/useMutation.d.cts +172 -0
  74. package/build/legacy/useMutation.d.cts.map +1 -1
  75. package/build/legacy/useMutation.d.ts +172 -0
  76. package/build/legacy/useMutation.d.ts.map +1 -1
  77. package/build/legacy/useMutation.js +172 -0
  78. package/build/legacy/useMutation.js.map +1 -1
  79. package/build/legacy/useMutationState.cjs +94 -0
  80. package/build/legacy/useMutationState.cjs.map +1 -1
  81. package/build/legacy/useMutationState.d.cts +94 -0
  82. package/build/legacy/useMutationState.d.cts.map +1 -1
  83. package/build/legacy/useMutationState.d.ts +94 -0
  84. package/build/legacy/useMutationState.d.ts.map +1 -1
  85. package/build/legacy/useMutationState.js +94 -0
  86. package/build/legacy/useMutationState.js.map +1 -1
  87. package/build/legacy/usePrefetchInfiniteQuery.cjs +44 -0
  88. package/build/legacy/usePrefetchInfiniteQuery.cjs.map +1 -1
  89. package/build/legacy/usePrefetchInfiniteQuery.d.cts +44 -0
  90. package/build/legacy/usePrefetchInfiniteQuery.d.cts.map +1 -1
  91. package/build/legacy/usePrefetchInfiniteQuery.d.ts +44 -0
  92. package/build/legacy/usePrefetchInfiniteQuery.d.ts.map +1 -1
  93. package/build/legacy/usePrefetchInfiniteQuery.js +44 -0
  94. package/build/legacy/usePrefetchInfiniteQuery.js.map +1 -1
  95. package/build/legacy/usePrefetchQuery.cjs +35 -0
  96. package/build/legacy/usePrefetchQuery.cjs.map +1 -1
  97. package/build/legacy/usePrefetchQuery.d.cts +35 -0
  98. package/build/legacy/usePrefetchQuery.d.cts.map +1 -1
  99. package/build/legacy/usePrefetchQuery.d.ts +35 -0
  100. package/build/legacy/usePrefetchQuery.d.ts.map +1 -1
  101. package/build/legacy/usePrefetchQuery.js +35 -0
  102. package/build/legacy/usePrefetchQuery.js.map +1 -1
  103. package/build/legacy/useQueries.cjs +130 -0
  104. package/build/legacy/useQueries.cjs.map +1 -1
  105. package/build/legacy/useQueries.d.cts +165 -2
  106. package/build/legacy/useQueries.d.cts.map +1 -1
  107. package/build/legacy/useQueries.d.ts +165 -2
  108. package/build/legacy/useQueries.d.ts.map +1 -1
  109. package/build/legacy/useQueries.js +130 -0
  110. package/build/legacy/useQueries.js.map +1 -1
  111. package/build/legacy/useQuery.cjs.map +1 -1
  112. package/build/legacy/useQuery.d.cts +246 -0
  113. package/build/legacy/useQuery.d.cts.map +1 -1
  114. package/build/legacy/useQuery.d.ts +246 -0
  115. package/build/legacy/useQuery.d.ts.map +1 -1
  116. package/build/legacy/useQuery.js.map +1 -1
  117. package/build/legacy/useSuspenseInfiniteQuery.cjs +86 -0
  118. package/build/legacy/useSuspenseInfiniteQuery.cjs.map +1 -1
  119. package/build/legacy/useSuspenseInfiniteQuery.d.cts +86 -0
  120. package/build/legacy/useSuspenseInfiniteQuery.d.cts.map +1 -1
  121. package/build/legacy/useSuspenseInfiniteQuery.d.ts +86 -0
  122. package/build/legacy/useSuspenseInfiniteQuery.d.ts.map +1 -1
  123. package/build/legacy/useSuspenseInfiniteQuery.js +86 -0
  124. package/build/legacy/useSuspenseInfiniteQuery.js.map +1 -1
  125. package/build/legacy/useSuspenseQueries.cjs.map +1 -1
  126. package/build/legacy/useSuspenseQueries.d.cts +320 -2
  127. package/build/legacy/useSuspenseQueries.d.cts.map +1 -1
  128. package/build/legacy/useSuspenseQueries.d.ts +320 -2
  129. package/build/legacy/useSuspenseQueries.d.ts.map +1 -1
  130. package/build/legacy/useSuspenseQueries.js.map +1 -1
  131. package/build/legacy/useSuspenseQuery.cjs +67 -0
  132. package/build/legacy/useSuspenseQuery.cjs.map +1 -1
  133. package/build/legacy/useSuspenseQuery.d.cts +67 -0
  134. package/build/legacy/useSuspenseQuery.d.cts.map +1 -1
  135. package/build/legacy/useSuspenseQuery.d.ts +67 -0
  136. package/build/legacy/useSuspenseQuery.d.ts.map +1 -1
  137. package/build/legacy/useSuspenseQuery.js +67 -0
  138. package/build/legacy/useSuspenseQuery.js.map +1 -1
  139. package/build/modern/HydrationBoundary.cjs +44 -1
  140. package/build/modern/HydrationBoundary.cjs.map +1 -1
  141. package/build/modern/HydrationBoundary.d.cts +61 -0
  142. package/build/modern/HydrationBoundary.d.cts.map +1 -1
  143. package/build/modern/HydrationBoundary.d.ts +61 -0
  144. package/build/modern/HydrationBoundary.d.ts.map +1 -1
  145. package/build/modern/HydrationBoundary.js +44 -1
  146. package/build/modern/HydrationBoundary.js.map +1 -1
  147. package/build/modern/IsRestoringProvider.cjs +11 -0
  148. package/build/modern/IsRestoringProvider.cjs.map +1 -1
  149. package/build/modern/IsRestoringProvider.d.cts +11 -0
  150. package/build/modern/IsRestoringProvider.d.cts.map +1 -1
  151. package/build/modern/IsRestoringProvider.d.ts +11 -0
  152. package/build/modern/IsRestoringProvider.d.ts.map +1 -1
  153. package/build/modern/IsRestoringProvider.js +11 -0
  154. package/build/modern/IsRestoringProvider.js.map +1 -1
  155. package/build/modern/QueryClientProvider.cjs +30 -0
  156. package/build/modern/QueryClientProvider.cjs.map +1 -1
  157. package/build/modern/QueryClientProvider.d.cts +41 -0
  158. package/build/modern/QueryClientProvider.d.cts.map +1 -1
  159. package/build/modern/QueryClientProvider.d.ts +41 -0
  160. package/build/modern/QueryClientProvider.d.ts.map +1 -1
  161. package/build/modern/QueryClientProvider.js +30 -0
  162. package/build/modern/QueryClientProvider.js.map +1 -1
  163. package/build/modern/QueryErrorResetBoundary.cjs +76 -0
  164. package/build/modern/QueryErrorResetBoundary.cjs.map +1 -1
  165. package/build/modern/QueryErrorResetBoundary.d.cts +77 -0
  166. package/build/modern/QueryErrorResetBoundary.d.cts.map +1 -1
  167. package/build/modern/QueryErrorResetBoundary.d.ts +77 -0
  168. package/build/modern/QueryErrorResetBoundary.d.ts.map +1 -1
  169. package/build/modern/QueryErrorResetBoundary.js +76 -0
  170. package/build/modern/QueryErrorResetBoundary.js.map +1 -1
  171. package/build/modern/infiniteQueryOptions.cjs.map +1 -1
  172. package/build/modern/infiniteQueryOptions.d.cts +173 -0
  173. package/build/modern/infiniteQueryOptions.d.cts.map +1 -1
  174. package/build/modern/infiniteQueryOptions.d.ts +173 -0
  175. package/build/modern/infiniteQueryOptions.d.ts.map +1 -1
  176. package/build/modern/infiniteQueryOptions.js.map +1 -1
  177. package/build/modern/mutationOptions.cjs.map +1 -1
  178. package/build/modern/mutationOptions.d.cts +55 -0
  179. package/build/modern/mutationOptions.d.cts.map +1 -1
  180. package/build/modern/mutationOptions.d.ts +55 -0
  181. package/build/modern/mutationOptions.d.ts.map +1 -1
  182. package/build/modern/mutationOptions.js.map +1 -1
  183. package/build/modern/queryOptions.cjs.map +1 -1
  184. package/build/modern/queryOptions.d.cts +175 -0
  185. package/build/modern/queryOptions.d.cts.map +1 -1
  186. package/build/modern/queryOptions.d.ts +175 -0
  187. package/build/modern/queryOptions.d.ts.map +1 -1
  188. package/build/modern/queryOptions.js.map +1 -1
  189. package/build/modern/types.cjs.map +1 -1
  190. package/build/modern/types.d.cts +228 -2
  191. package/build/modern/types.d.cts.map +1 -1
  192. package/build/modern/types.d.ts +228 -2
  193. package/build/modern/types.d.ts.map +1 -1
  194. package/build/modern/types.js.map +1 -1
  195. package/build/modern/useInfiniteQuery.cjs.map +1 -1
  196. package/build/modern/useInfiniteQuery.d.cts +292 -0
  197. package/build/modern/useInfiniteQuery.d.cts.map +1 -1
  198. package/build/modern/useInfiniteQuery.d.ts +292 -0
  199. package/build/modern/useInfiniteQuery.d.ts.map +1 -1
  200. package/build/modern/useInfiniteQuery.js.map +1 -1
  201. package/build/modern/useIsFetching.cjs +36 -0
  202. package/build/modern/useIsFetching.cjs.map +1 -1
  203. package/build/modern/useIsFetching.d.cts +36 -0
  204. package/build/modern/useIsFetching.d.cts.map +1 -1
  205. package/build/modern/useIsFetching.d.ts +36 -0
  206. package/build/modern/useIsFetching.d.ts.map +1 -1
  207. package/build/modern/useIsFetching.js +36 -0
  208. package/build/modern/useIsFetching.js.map +1 -1
  209. package/build/modern/useMutation.cjs +172 -0
  210. package/build/modern/useMutation.cjs.map +1 -1
  211. package/build/modern/useMutation.d.cts +172 -0
  212. package/build/modern/useMutation.d.cts.map +1 -1
  213. package/build/modern/useMutation.d.ts +172 -0
  214. package/build/modern/useMutation.d.ts.map +1 -1
  215. package/build/modern/useMutation.js +172 -0
  216. package/build/modern/useMutation.js.map +1 -1
  217. package/build/modern/useMutationState.cjs +94 -0
  218. package/build/modern/useMutationState.cjs.map +1 -1
  219. package/build/modern/useMutationState.d.cts +94 -0
  220. package/build/modern/useMutationState.d.cts.map +1 -1
  221. package/build/modern/useMutationState.d.ts +94 -0
  222. package/build/modern/useMutationState.d.ts.map +1 -1
  223. package/build/modern/useMutationState.js +94 -0
  224. package/build/modern/useMutationState.js.map +1 -1
  225. package/build/modern/usePrefetchInfiniteQuery.cjs +44 -0
  226. package/build/modern/usePrefetchInfiniteQuery.cjs.map +1 -1
  227. package/build/modern/usePrefetchInfiniteQuery.d.cts +44 -0
  228. package/build/modern/usePrefetchInfiniteQuery.d.cts.map +1 -1
  229. package/build/modern/usePrefetchInfiniteQuery.d.ts +44 -0
  230. package/build/modern/usePrefetchInfiniteQuery.d.ts.map +1 -1
  231. package/build/modern/usePrefetchInfiniteQuery.js +44 -0
  232. package/build/modern/usePrefetchInfiniteQuery.js.map +1 -1
  233. package/build/modern/usePrefetchQuery.cjs +35 -0
  234. package/build/modern/usePrefetchQuery.cjs.map +1 -1
  235. package/build/modern/usePrefetchQuery.d.cts +35 -0
  236. package/build/modern/usePrefetchQuery.d.cts.map +1 -1
  237. package/build/modern/usePrefetchQuery.d.ts +35 -0
  238. package/build/modern/usePrefetchQuery.d.ts.map +1 -1
  239. package/build/modern/usePrefetchQuery.js +35 -0
  240. package/build/modern/usePrefetchQuery.js.map +1 -1
  241. package/build/modern/useQueries.cjs +130 -0
  242. package/build/modern/useQueries.cjs.map +1 -1
  243. package/build/modern/useQueries.d.cts +165 -2
  244. package/build/modern/useQueries.d.cts.map +1 -1
  245. package/build/modern/useQueries.d.ts +165 -2
  246. package/build/modern/useQueries.d.ts.map +1 -1
  247. package/build/modern/useQueries.js +130 -0
  248. package/build/modern/useQueries.js.map +1 -1
  249. package/build/modern/useQuery.cjs.map +1 -1
  250. package/build/modern/useQuery.d.cts +246 -0
  251. package/build/modern/useQuery.d.cts.map +1 -1
  252. package/build/modern/useQuery.d.ts +246 -0
  253. package/build/modern/useQuery.d.ts.map +1 -1
  254. package/build/modern/useQuery.js.map +1 -1
  255. package/build/modern/useSuspenseInfiniteQuery.cjs +86 -0
  256. package/build/modern/useSuspenseInfiniteQuery.cjs.map +1 -1
  257. package/build/modern/useSuspenseInfiniteQuery.d.cts +86 -0
  258. package/build/modern/useSuspenseInfiniteQuery.d.cts.map +1 -1
  259. package/build/modern/useSuspenseInfiniteQuery.d.ts +86 -0
  260. package/build/modern/useSuspenseInfiniteQuery.d.ts.map +1 -1
  261. package/build/modern/useSuspenseInfiniteQuery.js +86 -0
  262. package/build/modern/useSuspenseInfiniteQuery.js.map +1 -1
  263. package/build/modern/useSuspenseQueries.cjs.map +1 -1
  264. package/build/modern/useSuspenseQueries.d.cts +320 -2
  265. package/build/modern/useSuspenseQueries.d.cts.map +1 -1
  266. package/build/modern/useSuspenseQueries.d.ts +320 -2
  267. package/build/modern/useSuspenseQueries.d.ts.map +1 -1
  268. package/build/modern/useSuspenseQueries.js.map +1 -1
  269. package/build/modern/useSuspenseQuery.cjs +67 -0
  270. package/build/modern/useSuspenseQuery.cjs.map +1 -1
  271. package/build/modern/useSuspenseQuery.d.cts +67 -0
  272. package/build/modern/useSuspenseQuery.d.cts.map +1 -1
  273. package/build/modern/useSuspenseQuery.d.ts +67 -0
  274. package/build/modern/useSuspenseQuery.d.ts.map +1 -1
  275. package/build/modern/useSuspenseQuery.js +67 -0
  276. package/build/modern/useSuspenseQuery.js.map +1 -1
  277. package/build/query-codemods/eslint.config.js +7 -0
  278. package/build/query-codemods/root.eslint.config.js +45 -0
  279. package/package.json +11 -11
  280. package/src/HydrationBoundary.tsx +61 -1
  281. package/src/IsRestoringProvider.ts +12 -0
  282. package/src/QueryClientProvider.tsx +41 -0
  283. package/src/QueryErrorResetBoundary.tsx +89 -0
  284. package/src/infiniteQueryOptions.ts +173 -0
  285. package/src/mutationOptions.ts +55 -0
  286. package/src/queryOptions.ts +175 -0
  287. package/src/types.ts +228 -2
  288. package/src/useInfiniteQuery.ts +292 -0
  289. package/src/useIsFetching.ts +36 -0
  290. package/src/useMutation.ts +172 -0
  291. package/src/useMutationState.ts +94 -0
  292. package/src/usePrefetchInfiniteQuery.tsx +44 -0
  293. package/src/usePrefetchQuery.tsx +35 -0
  294. package/src/useQueries.ts +165 -2
  295. package/src/useQuery.ts +246 -0
  296. package/src/useSuspenseInfiniteQuery.ts +86 -0
  297. package/src/useSuspenseQueries.ts +320 -2
  298. package/src/useSuspenseQuery.ts +67 -0
@@ -1 +1 @@
1
- {"version":3,"file":"useMutationState.js","names":[],"sources":["../../src/useMutationState.ts"],"sourcesContent":["'use client'\nimport * as React from 'react'\n\nimport { notifyManager, replaceEqualDeep } from '@tanstack/query-core'\nimport { useQueryClient } from './QueryClientProvider'\nimport type {\n Mutation,\n MutationCache,\n MutationFilters,\n MutationState,\n QueryClient,\n} from '@tanstack/query-core'\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\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 = React.useRef(options)\n const result = React.useRef<Array<TResult>>(null)\n if (result.current === null) {\n result.current = getResult(mutationCache, options)\n }\n\n React.useEffect(() => {\n optionsRef.current = options\n })\n\n return React.useSyncExternalStore(\n React.useCallback(\n (onStoreChange) =>\n mutationCache.subscribe(() => {\n const nextResult = replaceEqualDeep(\n result.current,\n getResult(mutationCache, optionsRef.current),\n )\n if (result.current !== nextResult) {\n result.current = nextResult\n notifyManager.schedule(onStoreChange)\n }\n }),\n [mutationCache],\n ),\n () => result.current,\n () => result.current,\n )!\n}\n"],"mappings":";;;;;AAaA,SAAgB,cACd,SACA,aACQ;CACR,MAAM,SAAS,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;AAEA,SAAgB,iBAKd,UAAoD,CAAC,GACrD,aACgB;CAChB,MAAM,gBAAgB,eAAe,WAAW,CAAC,CAAC,iBAAiB;CACnE,MAAM,aAAa,MAAM,OAAO,OAAO;CACvC,MAAM,SAAS,MAAM,OAAuB,IAAI;CAChD,IAAI,OAAO,YAAY,MACrB,OAAO,UAAU,UAAU,eAAe,OAAO;CAGnD,MAAM,gBAAgB;EACpB,WAAW,UAAU;CACvB,CAAC;CAED,OAAO,MAAM,qBACX,MAAM,aACH,kBACC,cAAc,gBAAgB;EAC5B,MAAM,aAAa,iBACjB,OAAO,SACP,UAAU,eAAe,WAAW,OAAO,CAC7C;EACA,IAAI,OAAO,YAAY,YAAY;GACjC,OAAO,UAAU;GACjB,cAAc,SAAS,aAAa;EACtC;CACF,CAAC,GACH,CAAC,aAAa,CAChB,SACM,OAAO,eACP,OAAO,OACf;AACF"}
1
+ {"version":3,"file":"useMutationState.js","names":[],"sources":["../../src/useMutationState.ts"],"sourcesContent":["'use client'\nimport * as React from 'react'\n\nimport { notifyManager, replaceEqualDeep } from '@tanstack/query-core'\nimport { useQueryClient } from './QueryClientProvider'\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 *\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/react-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/react-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/react-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/react-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 = React.useRef(options)\n const result = React.useRef<Array<TResult>>(null)\n if (result.current === null) {\n result.current = getResult(mutationCache, options)\n }\n\n React.useEffect(() => {\n optionsRef.current = options\n })\n\n return React.useSyncExternalStore(\n React.useCallback(\n (onStoreChange) =>\n mutationCache.subscribe(() => {\n const nextResult = replaceEqualDeep(\n result.current,\n getResult(mutationCache, optionsRef.current),\n )\n if (result.current !== nextResult) {\n result.current = nextResult\n notifyManager.schedule(onStoreChange)\n }\n }),\n [mutationCache],\n ),\n () => result.current,\n () => result.current,\n )!\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;AAkCA,SAAgB,cACd,SACA,aACQ;CACR,MAAM,SAAS,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,gBAAgB,eAAe,WAAW,CAAC,CAAC,iBAAiB;CACnE,MAAM,aAAa,MAAM,OAAO,OAAO;CACvC,MAAM,SAAS,MAAM,OAAuB,IAAI;CAChD,IAAI,OAAO,YAAY,MACrB,OAAO,UAAU,UAAU,eAAe,OAAO;CAGnD,MAAM,gBAAgB;EACpB,WAAW,UAAU;CACvB,CAAC;CAED,OAAO,MAAM,qBACX,MAAM,aACH,kBACC,cAAc,gBAAgB;EAC5B,MAAM,aAAa,iBACjB,OAAO,SACP,UAAU,eAAe,WAAW,OAAO,CAC7C;EACA,IAAI,OAAO,YAAY,YAAY;GACjC,OAAO,UAAU;GACjB,cAAc,SAAS,aAAa;EACtC;CACF,CAAC,GACH,CAAC,aAAa,CAChB,SACM,OAAO,eACP,OAAO,OACf;AACF"}
@@ -2,6 +2,50 @@ Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
2
2
  const require_QueryClientProvider = require("./QueryClientProvider.cjs");
3
3
  let _tanstack_query_core = require("@tanstack/query-core");
4
4
  //#region src/usePrefetchInfiniteQuery.tsx
5
+ /**
6
+ * `usePrefetchInfiniteQuery` does not return anything, it should be used just to fire a prefetch during render,
7
+ * before a suspense boundary that wraps a component that uses `useSuspenseInfiniteQuery`. You can pass
8
+ * everything to `usePrefetchInfiniteQuery` that you can pass to `queryClient.infiniteQuery`, though
9
+ * `queryKey`, `initialPageParam`, and `getNextPageParam` are always required, and `queryFn` is required unless
10
+ * a default query function has been defined.
11
+ *
12
+ * `getNextPageParam` receives both the last page of the infinite list of data and the full array of all pages,
13
+ * as well as pageParam information, and should return a single variable that will be passed to your query
14
+ * function as `context.pageParam`. Return `undefined` or `null` to indicate there is no next page available.
15
+ *
16
+ * The prefetch is skipped if the query already has any cached state — including a `pending`/`error` state left
17
+ * over from a previous attempt — so calling this on every render is cheap and won't refetch data that's
18
+ * already there or already in flight.
19
+ *
20
+ * @param options - The {@link UsePrefetchInfiniteQueryOptions} to use — everything you can pass to `queryClient.infiniteQuery`.
21
+ * @param queryClient - Use this to use a custom `QueryClient`. Otherwise, the one from the nearest context will
22
+ * be used.
23
+ * @returns `void` — nothing is returned.
24
+ *
25
+ * @example
26
+ * ```tsx
27
+ * import { Suspense } from 'react'
28
+ * import { infiniteQueryOptions, usePrefetchInfiniteQuery } from '@tanstack/react-query'
29
+ *
30
+ * const projectsOptions = infiniteQueryOptions({
31
+ * queryKey: ['projects'],
32
+ * queryFn: ({ pageParam }) => fetchProjects(pageParam),
33
+ * initialPageParam: 0,
34
+ * getNextPageParam: (lastPage) => lastPage.nextId,
35
+ * })
36
+ *
37
+ * function App() {
38
+ * // Fire the prefetch during render, before the suspense boundary below.
39
+ * usePrefetchInfiniteQuery(projectsOptions)
40
+ *
41
+ * return (
42
+ * <Suspense fallback={<h1>Loading projects...</h1>}>
43
+ * <Projects />
44
+ * </Suspense>
45
+ * )
46
+ * }
47
+ * ```
48
+ */
5
49
  function usePrefetchInfiniteQuery(options, queryClient) {
6
50
  const client = require_QueryClientProvider.useQueryClient(queryClient);
7
51
  if (!client.getQueryState(options.queryKey)) client.infiniteQuery(options).catch(_tanstack_query_core.noop);
@@ -1 +1 @@
1
- {"version":3,"file":"usePrefetchInfiniteQuery.cjs","names":["useQueryClient","noop"],"sources":["../../src/usePrefetchInfiniteQuery.tsx"],"sourcesContent":["import { noop } from '@tanstack/query-core'\nimport { useQueryClient } from './QueryClientProvider'\n\nimport type {\n DefaultError,\n InfiniteData,\n QueryClient,\n QueryKey,\n} from '@tanstack/query-core'\nimport type { UsePrefetchInfiniteQueryOptions } from './types'\n\nexport function usePrefetchInfiniteQuery<\n TQueryFnData = unknown,\n TError = DefaultError,\n TData = InfiniteData<TQueryFnData>,\n TQueryKey extends QueryKey = QueryKey,\n TPageParam = unknown,\n>(\n options: UsePrefetchInfiniteQueryOptions<\n TQueryFnData,\n TError,\n TData,\n TQueryKey,\n TPageParam\n >,\n queryClient?: QueryClient,\n): void {\n const client = useQueryClient(queryClient)\n\n if (!client.getQueryState(options.queryKey)) {\n void client.infiniteQuery(options).catch(noop)\n }\n}\n"],"mappings":";;;;AAWA,SAAgB,yBAOd,SAOA,aACM;CACN,MAAM,SAASA,4BAAAA,eAAe,WAAW;CAEzC,IAAI,CAAC,OAAO,cAAc,QAAQ,QAAQ,GACxC,OAAY,cAAc,OAAO,CAAC,CAAC,MAAMC,qBAAAA,IAAI;AAEjD"}
1
+ {"version":3,"file":"usePrefetchInfiniteQuery.cjs","names":["useQueryClient","noop"],"sources":["../../src/usePrefetchInfiniteQuery.tsx"],"sourcesContent":["import { noop } from '@tanstack/query-core'\nimport { useQueryClient } from './QueryClientProvider'\n\nimport type {\n DefaultError,\n InfiniteData,\n QueryClient,\n QueryKey,\n} from '@tanstack/query-core'\nimport type { UsePrefetchInfiniteQueryOptions } from './types'\n\n/**\n * `usePrefetchInfiniteQuery` does not return anything, it should be used just to fire a prefetch during render,\n * before a suspense boundary that wraps a component that uses `useSuspenseInfiniteQuery`. You can pass\n * everything to `usePrefetchInfiniteQuery` that you can pass to `queryClient.infiniteQuery`, though\n * `queryKey`, `initialPageParam`, and `getNextPageParam` are always required, and `queryFn` is required unless\n * a default query function has been defined.\n *\n * `getNextPageParam` receives both the last page of the infinite list of data and the full array of all pages,\n * as well as pageParam information, and should return a single variable that will be passed to your query\n * function as `context.pageParam`. Return `undefined` or `null` to indicate there is no next page available.\n *\n * The prefetch is skipped if the query already has any cached state — including a `pending`/`error` state left\n * over from a previous attempt — so calling this on every render is cheap and won't refetch data that's\n * already there or already in flight.\n *\n * @param options - The {@link UsePrefetchInfiniteQueryOptions} to use — everything you can pass to `queryClient.infiniteQuery`.\n * @param queryClient - Use this to use a custom `QueryClient`. Otherwise, the one from the nearest context will\n * be used.\n * @returns `void` — nothing is returned.\n *\n * @example\n * ```tsx\n * import { Suspense } from 'react'\n * import { infiniteQueryOptions, usePrefetchInfiniteQuery } from '@tanstack/react-query'\n *\n * const projectsOptions = infiniteQueryOptions({\n * queryKey: ['projects'],\n * queryFn: ({ pageParam }) => fetchProjects(pageParam),\n * initialPageParam: 0,\n * getNextPageParam: (lastPage) => lastPage.nextId,\n * })\n *\n * function App() {\n * // Fire the prefetch during render, before the suspense boundary below.\n * usePrefetchInfiniteQuery(projectsOptions)\n *\n * return (\n * <Suspense fallback={<h1>Loading projects...</h1>}>\n * <Projects />\n * </Suspense>\n * )\n * }\n * ```\n */\nexport function usePrefetchInfiniteQuery<\n TQueryFnData = unknown,\n TError = DefaultError,\n TData = InfiniteData<TQueryFnData>,\n TQueryKey extends QueryKey = QueryKey,\n TPageParam = unknown,\n>(\n options: UsePrefetchInfiniteQueryOptions<\n TQueryFnData,\n TError,\n TData,\n TQueryKey,\n TPageParam\n >,\n queryClient?: QueryClient,\n): void {\n const client = useQueryClient(queryClient)\n\n if (!client.getQueryState(options.queryKey)) {\n void client.infiniteQuery(options).catch(noop)\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAuDA,SAAgB,yBAOd,SAOA,aACM;CACN,MAAM,SAASA,4BAAAA,eAAe,WAAW;CAEzC,IAAI,CAAC,OAAO,cAAc,QAAQ,QAAQ,GACxC,OAAY,cAAc,OAAO,CAAC,CAAC,MAAMC,qBAAAA,IAAI;AAEjD"}
@@ -1,6 +1,50 @@
1
1
  import { UsePrefetchInfiniteQueryOptions } from "./types.cjs";
2
2
  import { DefaultError, InfiniteData, QueryClient, QueryKey } from "@tanstack/query-core";
3
3
  //#region src/usePrefetchInfiniteQuery.d.ts
4
+ /**
5
+ * `usePrefetchInfiniteQuery` does not return anything, it should be used just to fire a prefetch during render,
6
+ * before a suspense boundary that wraps a component that uses `useSuspenseInfiniteQuery`. You can pass
7
+ * everything to `usePrefetchInfiniteQuery` that you can pass to `queryClient.infiniteQuery`, though
8
+ * `queryKey`, `initialPageParam`, and `getNextPageParam` are always required, and `queryFn` is required unless
9
+ * a default query function has been defined.
10
+ *
11
+ * `getNextPageParam` receives both the last page of the infinite list of data and the full array of all pages,
12
+ * as well as pageParam information, and should return a single variable that will be passed to your query
13
+ * function as `context.pageParam`. Return `undefined` or `null` to indicate there is no next page available.
14
+ *
15
+ * The prefetch is skipped if the query already has any cached state — including a `pending`/`error` state left
16
+ * over from a previous attempt — so calling this on every render is cheap and won't refetch data that's
17
+ * already there or already in flight.
18
+ *
19
+ * @param options - The {@link UsePrefetchInfiniteQueryOptions} to use — everything you can pass to `queryClient.infiniteQuery`.
20
+ * @param queryClient - Use this to use a custom `QueryClient`. Otherwise, the one from the nearest context will
21
+ * be used.
22
+ * @returns `void` — nothing is returned.
23
+ *
24
+ * @example
25
+ * ```tsx
26
+ * import { Suspense } from 'react'
27
+ * import { infiniteQueryOptions, usePrefetchInfiniteQuery } from '@tanstack/react-query'
28
+ *
29
+ * const projectsOptions = infiniteQueryOptions({
30
+ * queryKey: ['projects'],
31
+ * queryFn: ({ pageParam }) => fetchProjects(pageParam),
32
+ * initialPageParam: 0,
33
+ * getNextPageParam: (lastPage) => lastPage.nextId,
34
+ * })
35
+ *
36
+ * function App() {
37
+ * // Fire the prefetch during render, before the suspense boundary below.
38
+ * usePrefetchInfiniteQuery(projectsOptions)
39
+ *
40
+ * return (
41
+ * <Suspense fallback={<h1>Loading projects...</h1>}>
42
+ * <Projects />
43
+ * </Suspense>
44
+ * )
45
+ * }
46
+ * ```
47
+ */
4
48
  declare function usePrefetchInfiniteQuery<TQueryFnData = unknown, TError = DefaultError, TData = InfiniteData<TQueryFnData>, TQueryKey extends QueryKey = QueryKey, TPageParam = unknown>(options: UsePrefetchInfiniteQueryOptions<TQueryFnData, TError, TData, TQueryKey, TPageParam>, queryClient?: QueryClient): void;
5
49
  //#endregion
6
50
  export { usePrefetchInfiniteQuery };
@@ -1 +1 @@
1
- {"version":3,"file":"usePrefetchInfiniteQuery.d.cts","names":[],"sources":["../../src/usePrefetchInfiniteQuery.tsx"],"mappings":";;;iBAWgB,yBACd,wBACA,SAAS,cACT,QAAQ,aAAa,eACrB,kBAAkB,WAAW,UAC7B,sBAEA,SAAS,gCACP,cACA,QACA,OACA,WACA,aAEF,cAAc"}
1
+ {"version":3,"file":"usePrefetchInfiniteQuery.d.cts","names":[],"sources":["../../src/usePrefetchInfiniteQuery.tsx"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;iBAuDgB,yBACd,wBACA,SAAS,cACT,QAAQ,aAAa,eACrB,kBAAkB,WAAW,UAC7B,sBAEA,SAAS,gCACP,cACA,QACA,OACA,WACA,aAEF,cAAc"}
@@ -1,6 +1,50 @@
1
1
  import { UsePrefetchInfiniteQueryOptions } from "./types.js";
2
2
  import { DefaultError, InfiniteData, QueryClient, QueryKey } from "@tanstack/query-core";
3
3
  //#region src/usePrefetchInfiniteQuery.d.ts
4
+ /**
5
+ * `usePrefetchInfiniteQuery` does not return anything, it should be used just to fire a prefetch during render,
6
+ * before a suspense boundary that wraps a component that uses `useSuspenseInfiniteQuery`. You can pass
7
+ * everything to `usePrefetchInfiniteQuery` that you can pass to `queryClient.infiniteQuery`, though
8
+ * `queryKey`, `initialPageParam`, and `getNextPageParam` are always required, and `queryFn` is required unless
9
+ * a default query function has been defined.
10
+ *
11
+ * `getNextPageParam` receives both the last page of the infinite list of data and the full array of all pages,
12
+ * as well as pageParam information, and should return a single variable that will be passed to your query
13
+ * function as `context.pageParam`. Return `undefined` or `null` to indicate there is no next page available.
14
+ *
15
+ * The prefetch is skipped if the query already has any cached state — including a `pending`/`error` state left
16
+ * over from a previous attempt — so calling this on every render is cheap and won't refetch data that's
17
+ * already there or already in flight.
18
+ *
19
+ * @param options - The {@link UsePrefetchInfiniteQueryOptions} to use — everything you can pass to `queryClient.infiniteQuery`.
20
+ * @param queryClient - Use this to use a custom `QueryClient`. Otherwise, the one from the nearest context will
21
+ * be used.
22
+ * @returns `void` — nothing is returned.
23
+ *
24
+ * @example
25
+ * ```tsx
26
+ * import { Suspense } from 'react'
27
+ * import { infiniteQueryOptions, usePrefetchInfiniteQuery } from '@tanstack/react-query'
28
+ *
29
+ * const projectsOptions = infiniteQueryOptions({
30
+ * queryKey: ['projects'],
31
+ * queryFn: ({ pageParam }) => fetchProjects(pageParam),
32
+ * initialPageParam: 0,
33
+ * getNextPageParam: (lastPage) => lastPage.nextId,
34
+ * })
35
+ *
36
+ * function App() {
37
+ * // Fire the prefetch during render, before the suspense boundary below.
38
+ * usePrefetchInfiniteQuery(projectsOptions)
39
+ *
40
+ * return (
41
+ * <Suspense fallback={<h1>Loading projects...</h1>}>
42
+ * <Projects />
43
+ * </Suspense>
44
+ * )
45
+ * }
46
+ * ```
47
+ */
4
48
  declare function usePrefetchInfiniteQuery<TQueryFnData = unknown, TError = DefaultError, TData = InfiniteData<TQueryFnData>, TQueryKey extends QueryKey = QueryKey, TPageParam = unknown>(options: UsePrefetchInfiniteQueryOptions<TQueryFnData, TError, TData, TQueryKey, TPageParam>, queryClient?: QueryClient): void;
5
49
  //#endregion
6
50
  export { usePrefetchInfiniteQuery };
@@ -1 +1 @@
1
- {"version":3,"file":"usePrefetchInfiniteQuery.d.ts","names":[],"sources":["../../src/usePrefetchInfiniteQuery.tsx"],"mappings":";;;iBAWgB,yBACd,wBACA,SAAS,cACT,QAAQ,aAAa,eACrB,kBAAkB,WAAW,UAC7B,sBAEA,SAAS,gCACP,cACA,QACA,OACA,WACA,aAEF,cAAc"}
1
+ {"version":3,"file":"usePrefetchInfiniteQuery.d.ts","names":[],"sources":["../../src/usePrefetchInfiniteQuery.tsx"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;iBAuDgB,yBACd,wBACA,SAAS,cACT,QAAQ,aAAa,eACrB,kBAAkB,WAAW,UAC7B,sBAEA,SAAS,gCACP,cACA,QACA,OACA,WACA,aAEF,cAAc"}
@@ -1,6 +1,50 @@
1
1
  import { useQueryClient } from "./QueryClientProvider.js";
2
2
  import { noop } from "@tanstack/query-core";
3
3
  //#region src/usePrefetchInfiniteQuery.tsx
4
+ /**
5
+ * `usePrefetchInfiniteQuery` does not return anything, it should be used just to fire a prefetch during render,
6
+ * before a suspense boundary that wraps a component that uses `useSuspenseInfiniteQuery`. You can pass
7
+ * everything to `usePrefetchInfiniteQuery` that you can pass to `queryClient.infiniteQuery`, though
8
+ * `queryKey`, `initialPageParam`, and `getNextPageParam` are always required, and `queryFn` is required unless
9
+ * a default query function has been defined.
10
+ *
11
+ * `getNextPageParam` receives both the last page of the infinite list of data and the full array of all pages,
12
+ * as well as pageParam information, and should return a single variable that will be passed to your query
13
+ * function as `context.pageParam`. Return `undefined` or `null` to indicate there is no next page available.
14
+ *
15
+ * The prefetch is skipped if the query already has any cached state — including a `pending`/`error` state left
16
+ * over from a previous attempt — so calling this on every render is cheap and won't refetch data that's
17
+ * already there or already in flight.
18
+ *
19
+ * @param options - The {@link UsePrefetchInfiniteQueryOptions} to use — everything you can pass to `queryClient.infiniteQuery`.
20
+ * @param queryClient - Use this to use a custom `QueryClient`. Otherwise, the one from the nearest context will
21
+ * be used.
22
+ * @returns `void` — nothing is returned.
23
+ *
24
+ * @example
25
+ * ```tsx
26
+ * import { Suspense } from 'react'
27
+ * import { infiniteQueryOptions, usePrefetchInfiniteQuery } from '@tanstack/react-query'
28
+ *
29
+ * const projectsOptions = infiniteQueryOptions({
30
+ * queryKey: ['projects'],
31
+ * queryFn: ({ pageParam }) => fetchProjects(pageParam),
32
+ * initialPageParam: 0,
33
+ * getNextPageParam: (lastPage) => lastPage.nextId,
34
+ * })
35
+ *
36
+ * function App() {
37
+ * // Fire the prefetch during render, before the suspense boundary below.
38
+ * usePrefetchInfiniteQuery(projectsOptions)
39
+ *
40
+ * return (
41
+ * <Suspense fallback={<h1>Loading projects...</h1>}>
42
+ * <Projects />
43
+ * </Suspense>
44
+ * )
45
+ * }
46
+ * ```
47
+ */
4
48
  function usePrefetchInfiniteQuery(options, queryClient) {
5
49
  const client = useQueryClient(queryClient);
6
50
  if (!client.getQueryState(options.queryKey)) client.infiniteQuery(options).catch(noop);
@@ -1 +1 @@
1
- {"version":3,"file":"usePrefetchInfiniteQuery.js","names":[],"sources":["../../src/usePrefetchInfiniteQuery.tsx"],"sourcesContent":["import { noop } from '@tanstack/query-core'\nimport { useQueryClient } from './QueryClientProvider'\n\nimport type {\n DefaultError,\n InfiniteData,\n QueryClient,\n QueryKey,\n} from '@tanstack/query-core'\nimport type { UsePrefetchInfiniteQueryOptions } from './types'\n\nexport function usePrefetchInfiniteQuery<\n TQueryFnData = unknown,\n TError = DefaultError,\n TData = InfiniteData<TQueryFnData>,\n TQueryKey extends QueryKey = QueryKey,\n TPageParam = unknown,\n>(\n options: UsePrefetchInfiniteQueryOptions<\n TQueryFnData,\n TError,\n TData,\n TQueryKey,\n TPageParam\n >,\n queryClient?: QueryClient,\n): void {\n const client = useQueryClient(queryClient)\n\n if (!client.getQueryState(options.queryKey)) {\n void client.infiniteQuery(options).catch(noop)\n }\n}\n"],"mappings":";;;AAWA,SAAgB,yBAOd,SAOA,aACM;CACN,MAAM,SAAS,eAAe,WAAW;CAEzC,IAAI,CAAC,OAAO,cAAc,QAAQ,QAAQ,GACxC,OAAY,cAAc,OAAO,CAAC,CAAC,MAAM,IAAI;AAEjD"}
1
+ {"version":3,"file":"usePrefetchInfiniteQuery.js","names":[],"sources":["../../src/usePrefetchInfiniteQuery.tsx"],"sourcesContent":["import { noop } from '@tanstack/query-core'\nimport { useQueryClient } from './QueryClientProvider'\n\nimport type {\n DefaultError,\n InfiniteData,\n QueryClient,\n QueryKey,\n} from '@tanstack/query-core'\nimport type { UsePrefetchInfiniteQueryOptions } from './types'\n\n/**\n * `usePrefetchInfiniteQuery` does not return anything, it should be used just to fire a prefetch during render,\n * before a suspense boundary that wraps a component that uses `useSuspenseInfiniteQuery`. You can pass\n * everything to `usePrefetchInfiniteQuery` that you can pass to `queryClient.infiniteQuery`, though\n * `queryKey`, `initialPageParam`, and `getNextPageParam` are always required, and `queryFn` is required unless\n * a default query function has been defined.\n *\n * `getNextPageParam` receives both the last page of the infinite list of data and the full array of all pages,\n * as well as pageParam information, and should return a single variable that will be passed to your query\n * function as `context.pageParam`. Return `undefined` or `null` to indicate there is no next page available.\n *\n * The prefetch is skipped if the query already has any cached state — including a `pending`/`error` state left\n * over from a previous attempt — so calling this on every render is cheap and won't refetch data that's\n * already there or already in flight.\n *\n * @param options - The {@link UsePrefetchInfiniteQueryOptions} to use — everything you can pass to `queryClient.infiniteQuery`.\n * @param queryClient - Use this to use a custom `QueryClient`. Otherwise, the one from the nearest context will\n * be used.\n * @returns `void` — nothing is returned.\n *\n * @example\n * ```tsx\n * import { Suspense } from 'react'\n * import { infiniteQueryOptions, usePrefetchInfiniteQuery } from '@tanstack/react-query'\n *\n * const projectsOptions = infiniteQueryOptions({\n * queryKey: ['projects'],\n * queryFn: ({ pageParam }) => fetchProjects(pageParam),\n * initialPageParam: 0,\n * getNextPageParam: (lastPage) => lastPage.nextId,\n * })\n *\n * function App() {\n * // Fire the prefetch during render, before the suspense boundary below.\n * usePrefetchInfiniteQuery(projectsOptions)\n *\n * return (\n * <Suspense fallback={<h1>Loading projects...</h1>}>\n * <Projects />\n * </Suspense>\n * )\n * }\n * ```\n */\nexport function usePrefetchInfiniteQuery<\n TQueryFnData = unknown,\n TError = DefaultError,\n TData = InfiniteData<TQueryFnData>,\n TQueryKey extends QueryKey = QueryKey,\n TPageParam = unknown,\n>(\n options: UsePrefetchInfiniteQueryOptions<\n TQueryFnData,\n TError,\n TData,\n TQueryKey,\n TPageParam\n >,\n queryClient?: QueryClient,\n): void {\n const client = useQueryClient(queryClient)\n\n if (!client.getQueryState(options.queryKey)) {\n void client.infiniteQuery(options).catch(noop)\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAuDA,SAAgB,yBAOd,SAOA,aACM;CACN,MAAM,SAAS,eAAe,WAAW;CAEzC,IAAI,CAAC,OAAO,cAAc,QAAQ,QAAQ,GACxC,OAAY,cAAc,OAAO,CAAC,CAAC,MAAM,IAAI;AAEjD"}
@@ -2,6 +2,41 @@ Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
2
2
  const require_QueryClientProvider = require("./QueryClientProvider.cjs");
3
3
  let _tanstack_query_core = require("@tanstack/query-core");
4
4
  //#region src/usePrefetchQuery.tsx
5
+ /**
6
+ * `usePrefetchQuery` does not return anything, it should be used just to fire a prefetch during render, before
7
+ * a suspense boundary that wraps a component that uses `useSuspenseQuery`. You can pass everything to
8
+ * `usePrefetchQuery` that you can pass to `queryClient.query`, though `queryKey` is always required, and
9
+ * `queryFn` is required unless a default query function has been defined.
10
+ *
11
+ * The prefetch is skipped if the query already has any cached state — including a `pending`/`error` state left
12
+ * over from a previous attempt — so calling this on every render is cheap and won't refetch data that's
13
+ * already there or already in flight.
14
+ *
15
+ * @param options - The {@link UsePrefetchQueryOptions} to use — everything you can pass to `queryClient.query`.
16
+ * @param queryClient - Use this to use a custom `QueryClient`. Otherwise, the one from the nearest context will
17
+ * be used.
18
+ * @returns `void` — nothing is returned.
19
+ *
20
+ * @example
21
+ * ```tsx
22
+ * import { Suspense } from 'react'
23
+ * import { usePrefetchQuery } from '@tanstack/react-query'
24
+ *
25
+ * function App() {
26
+ * // Fire the prefetch during render, before the suspense boundary below.
27
+ * usePrefetchQuery({
28
+ * queryKey: ['posts'],
29
+ * queryFn: fetchPosts,
30
+ * })
31
+ *
32
+ * return (
33
+ * <Suspense fallback={<h1>Loading posts...</h1>}>
34
+ * <Posts />
35
+ * </Suspense>
36
+ * )
37
+ * }
38
+ * ```
39
+ */
5
40
  function usePrefetchQuery(options, queryClient) {
6
41
  const client = require_QueryClientProvider.useQueryClient(queryClient);
7
42
  if (!client.getQueryState(options.queryKey)) client.query(options).catch(_tanstack_query_core.noop);
@@ -1 +1 @@
1
- {"version":3,"file":"usePrefetchQuery.cjs","names":["useQueryClient","noop"],"sources":["../../src/usePrefetchQuery.tsx"],"sourcesContent":["import { noop } from '@tanstack/query-core'\nimport { useQueryClient } from './QueryClientProvider'\n\nimport type { DefaultError, QueryClient, QueryKey } from '@tanstack/query-core'\nimport type { UsePrefetchQueryOptions } from './types'\n\nexport function usePrefetchQuery<\n TQueryFnData = unknown,\n TError = DefaultError,\n TData = TQueryFnData,\n TQueryData = TQueryFnData,\n TQueryKey extends QueryKey = QueryKey,\n>(\n options: UsePrefetchQueryOptions<\n TQueryFnData,\n TError,\n TData,\n TQueryData,\n TQueryKey\n >,\n queryClient?: QueryClient,\n): void {\n const client = useQueryClient(queryClient)\n\n if (!client.getQueryState(options.queryKey)) {\n void client.query(options).catch(noop)\n }\n}\n"],"mappings":";;;;AAMA,SAAgB,iBAOd,SAOA,aACM;CACN,MAAM,SAASA,4BAAAA,eAAe,WAAW;CAEzC,IAAI,CAAC,OAAO,cAAc,QAAQ,QAAQ,GACxC,OAAY,MAAM,OAAO,CAAC,CAAC,MAAMC,qBAAAA,IAAI;AAEzC"}
1
+ {"version":3,"file":"usePrefetchQuery.cjs","names":["useQueryClient","noop"],"sources":["../../src/usePrefetchQuery.tsx"],"sourcesContent":["import { noop } from '@tanstack/query-core'\nimport { useQueryClient } from './QueryClientProvider'\n\nimport type { DefaultError, QueryClient, QueryKey } from '@tanstack/query-core'\nimport type { UsePrefetchQueryOptions } from './types'\n\n/**\n * `usePrefetchQuery` does not return anything, it should be used just to fire a prefetch during render, before\n * a suspense boundary that wraps a component that uses `useSuspenseQuery`. You can pass everything to\n * `usePrefetchQuery` that you can pass to `queryClient.query`, though `queryKey` is always required, and\n * `queryFn` is required unless a default query function has been defined.\n *\n * The prefetch is skipped if the query already has any cached state — including a `pending`/`error` state left\n * over from a previous attempt — so calling this on every render is cheap and won't refetch data that's\n * already there or already in flight.\n *\n * @param options - The {@link UsePrefetchQueryOptions} to use — everything you can pass to `queryClient.query`.\n * @param queryClient - Use this to use a custom `QueryClient`. Otherwise, the one from the nearest context will\n * be used.\n * @returns `void` — nothing is returned.\n *\n * @example\n * ```tsx\n * import { Suspense } from 'react'\n * import { usePrefetchQuery } from '@tanstack/react-query'\n *\n * function App() {\n * // Fire the prefetch during render, before the suspense boundary below.\n * usePrefetchQuery({\n * queryKey: ['posts'],\n * queryFn: fetchPosts,\n * })\n *\n * return (\n * <Suspense fallback={<h1>Loading posts...</h1>}>\n * <Posts />\n * </Suspense>\n * )\n * }\n * ```\n */\nexport function usePrefetchQuery<\n TQueryFnData = unknown,\n TError = DefaultError,\n TData = TQueryFnData,\n TQueryData = TQueryFnData,\n TQueryKey extends QueryKey = QueryKey,\n>(\n options: UsePrefetchQueryOptions<\n TQueryFnData,\n TError,\n TData,\n TQueryData,\n TQueryKey\n >,\n queryClient?: QueryClient,\n): void {\n const client = useQueryClient(queryClient)\n\n if (!client.getQueryState(options.queryKey)) {\n void client.query(options).catch(noop)\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAyCA,SAAgB,iBAOd,SAOA,aACM;CACN,MAAM,SAASA,4BAAAA,eAAe,WAAW;CAEzC,IAAI,CAAC,OAAO,cAAc,QAAQ,QAAQ,GACxC,OAAY,MAAM,OAAO,CAAC,CAAC,MAAMC,qBAAAA,IAAI;AAEzC"}
@@ -1,6 +1,41 @@
1
1
  import { UsePrefetchQueryOptions } from "./types.cjs";
2
2
  import { DefaultError, QueryClient, QueryKey } from "@tanstack/query-core";
3
3
  //#region src/usePrefetchQuery.d.ts
4
+ /**
5
+ * `usePrefetchQuery` does not return anything, it should be used just to fire a prefetch during render, before
6
+ * a suspense boundary that wraps a component that uses `useSuspenseQuery`. You can pass everything to
7
+ * `usePrefetchQuery` that you can pass to `queryClient.query`, though `queryKey` is always required, and
8
+ * `queryFn` is required unless a default query function has been defined.
9
+ *
10
+ * The prefetch is skipped if the query already has any cached state — including a `pending`/`error` state left
11
+ * over from a previous attempt — so calling this on every render is cheap and won't refetch data that's
12
+ * already there or already in flight.
13
+ *
14
+ * @param options - The {@link UsePrefetchQueryOptions} to use — everything you can pass to `queryClient.query`.
15
+ * @param queryClient - Use this to use a custom `QueryClient`. Otherwise, the one from the nearest context will
16
+ * be used.
17
+ * @returns `void` — nothing is returned.
18
+ *
19
+ * @example
20
+ * ```tsx
21
+ * import { Suspense } from 'react'
22
+ * import { usePrefetchQuery } from '@tanstack/react-query'
23
+ *
24
+ * function App() {
25
+ * // Fire the prefetch during render, before the suspense boundary below.
26
+ * usePrefetchQuery({
27
+ * queryKey: ['posts'],
28
+ * queryFn: fetchPosts,
29
+ * })
30
+ *
31
+ * return (
32
+ * <Suspense fallback={<h1>Loading posts...</h1>}>
33
+ * <Posts />
34
+ * </Suspense>
35
+ * )
36
+ * }
37
+ * ```
38
+ */
4
39
  declare function usePrefetchQuery<TQueryFnData = unknown, TError = DefaultError, TData = TQueryFnData, TQueryData = TQueryFnData, TQueryKey extends QueryKey = QueryKey>(options: UsePrefetchQueryOptions<TQueryFnData, TError, TData, TQueryData, TQueryKey>, queryClient?: QueryClient): void;
5
40
  //#endregion
6
41
  export { usePrefetchQuery };
@@ -1 +1 @@
1
- {"version":3,"file":"usePrefetchQuery.d.cts","names":[],"sources":["../../src/usePrefetchQuery.tsx"],"mappings":";;;iBAMgB,iBACd,wBACA,SAAS,cACT,QAAQ,cACR,aAAa,cACb,kBAAkB,WAAW,UAE7B,SAAS,wBACP,cACA,QACA,OACA,YACA,YAEF,cAAc"}
1
+ {"version":3,"file":"usePrefetchQuery.d.cts","names":[],"sources":["../../src/usePrefetchQuery.tsx"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;iBAyCgB,iBACd,wBACA,SAAS,cACT,QAAQ,cACR,aAAa,cACb,kBAAkB,WAAW,UAE7B,SAAS,wBACP,cACA,QACA,OACA,YACA,YAEF,cAAc"}
@@ -1,6 +1,41 @@
1
1
  import { UsePrefetchQueryOptions } from "./types.js";
2
2
  import { DefaultError, QueryClient, QueryKey } from "@tanstack/query-core";
3
3
  //#region src/usePrefetchQuery.d.ts
4
+ /**
5
+ * `usePrefetchQuery` does not return anything, it should be used just to fire a prefetch during render, before
6
+ * a suspense boundary that wraps a component that uses `useSuspenseQuery`. You can pass everything to
7
+ * `usePrefetchQuery` that you can pass to `queryClient.query`, though `queryKey` is always required, and
8
+ * `queryFn` is required unless a default query function has been defined.
9
+ *
10
+ * The prefetch is skipped if the query already has any cached state — including a `pending`/`error` state left
11
+ * over from a previous attempt — so calling this on every render is cheap and won't refetch data that's
12
+ * already there or already in flight.
13
+ *
14
+ * @param options - The {@link UsePrefetchQueryOptions} to use — everything you can pass to `queryClient.query`.
15
+ * @param queryClient - Use this to use a custom `QueryClient`. Otherwise, the one from the nearest context will
16
+ * be used.
17
+ * @returns `void` — nothing is returned.
18
+ *
19
+ * @example
20
+ * ```tsx
21
+ * import { Suspense } from 'react'
22
+ * import { usePrefetchQuery } from '@tanstack/react-query'
23
+ *
24
+ * function App() {
25
+ * // Fire the prefetch during render, before the suspense boundary below.
26
+ * usePrefetchQuery({
27
+ * queryKey: ['posts'],
28
+ * queryFn: fetchPosts,
29
+ * })
30
+ *
31
+ * return (
32
+ * <Suspense fallback={<h1>Loading posts...</h1>}>
33
+ * <Posts />
34
+ * </Suspense>
35
+ * )
36
+ * }
37
+ * ```
38
+ */
4
39
  declare function usePrefetchQuery<TQueryFnData = unknown, TError = DefaultError, TData = TQueryFnData, TQueryData = TQueryFnData, TQueryKey extends QueryKey = QueryKey>(options: UsePrefetchQueryOptions<TQueryFnData, TError, TData, TQueryData, TQueryKey>, queryClient?: QueryClient): void;
5
40
  //#endregion
6
41
  export { usePrefetchQuery };
@@ -1 +1 @@
1
- {"version":3,"file":"usePrefetchQuery.d.ts","names":[],"sources":["../../src/usePrefetchQuery.tsx"],"mappings":";;;iBAMgB,iBACd,wBACA,SAAS,cACT,QAAQ,cACR,aAAa,cACb,kBAAkB,WAAW,UAE7B,SAAS,wBACP,cACA,QACA,OACA,YACA,YAEF,cAAc"}
1
+ {"version":3,"file":"usePrefetchQuery.d.ts","names":[],"sources":["../../src/usePrefetchQuery.tsx"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;iBAyCgB,iBACd,wBACA,SAAS,cACT,QAAQ,cACR,aAAa,cACb,kBAAkB,WAAW,UAE7B,SAAS,wBACP,cACA,QACA,OACA,YACA,YAEF,cAAc"}
@@ -1,6 +1,41 @@
1
1
  import { useQueryClient } from "./QueryClientProvider.js";
2
2
  import { noop } from "@tanstack/query-core";
3
3
  //#region src/usePrefetchQuery.tsx
4
+ /**
5
+ * `usePrefetchQuery` does not return anything, it should be used just to fire a prefetch during render, before
6
+ * a suspense boundary that wraps a component that uses `useSuspenseQuery`. You can pass everything to
7
+ * `usePrefetchQuery` that you can pass to `queryClient.query`, though `queryKey` is always required, and
8
+ * `queryFn` is required unless a default query function has been defined.
9
+ *
10
+ * The prefetch is skipped if the query already has any cached state — including a `pending`/`error` state left
11
+ * over from a previous attempt — so calling this on every render is cheap and won't refetch data that's
12
+ * already there or already in flight.
13
+ *
14
+ * @param options - The {@link UsePrefetchQueryOptions} to use — everything you can pass to `queryClient.query`.
15
+ * @param queryClient - Use this to use a custom `QueryClient`. Otherwise, the one from the nearest context will
16
+ * be used.
17
+ * @returns `void` — nothing is returned.
18
+ *
19
+ * @example
20
+ * ```tsx
21
+ * import { Suspense } from 'react'
22
+ * import { usePrefetchQuery } from '@tanstack/react-query'
23
+ *
24
+ * function App() {
25
+ * // Fire the prefetch during render, before the suspense boundary below.
26
+ * usePrefetchQuery({
27
+ * queryKey: ['posts'],
28
+ * queryFn: fetchPosts,
29
+ * })
30
+ *
31
+ * return (
32
+ * <Suspense fallback={<h1>Loading posts...</h1>}>
33
+ * <Posts />
34
+ * </Suspense>
35
+ * )
36
+ * }
37
+ * ```
38
+ */
4
39
  function usePrefetchQuery(options, queryClient) {
5
40
  const client = useQueryClient(queryClient);
6
41
  if (!client.getQueryState(options.queryKey)) client.query(options).catch(noop);
@@ -1 +1 @@
1
- {"version":3,"file":"usePrefetchQuery.js","names":[],"sources":["../../src/usePrefetchQuery.tsx"],"sourcesContent":["import { noop } from '@tanstack/query-core'\nimport { useQueryClient } from './QueryClientProvider'\n\nimport type { DefaultError, QueryClient, QueryKey } from '@tanstack/query-core'\nimport type { UsePrefetchQueryOptions } from './types'\n\nexport function usePrefetchQuery<\n TQueryFnData = unknown,\n TError = DefaultError,\n TData = TQueryFnData,\n TQueryData = TQueryFnData,\n TQueryKey extends QueryKey = QueryKey,\n>(\n options: UsePrefetchQueryOptions<\n TQueryFnData,\n TError,\n TData,\n TQueryData,\n TQueryKey\n >,\n queryClient?: QueryClient,\n): void {\n const client = useQueryClient(queryClient)\n\n if (!client.getQueryState(options.queryKey)) {\n void client.query(options).catch(noop)\n }\n}\n"],"mappings":";;;AAMA,SAAgB,iBAOd,SAOA,aACM;CACN,MAAM,SAAS,eAAe,WAAW;CAEzC,IAAI,CAAC,OAAO,cAAc,QAAQ,QAAQ,GACxC,OAAY,MAAM,OAAO,CAAC,CAAC,MAAM,IAAI;AAEzC"}
1
+ {"version":3,"file":"usePrefetchQuery.js","names":[],"sources":["../../src/usePrefetchQuery.tsx"],"sourcesContent":["import { noop } from '@tanstack/query-core'\nimport { useQueryClient } from './QueryClientProvider'\n\nimport type { DefaultError, QueryClient, QueryKey } from '@tanstack/query-core'\nimport type { UsePrefetchQueryOptions } from './types'\n\n/**\n * `usePrefetchQuery` does not return anything, it should be used just to fire a prefetch during render, before\n * a suspense boundary that wraps a component that uses `useSuspenseQuery`. You can pass everything to\n * `usePrefetchQuery` that you can pass to `queryClient.query`, though `queryKey` is always required, and\n * `queryFn` is required unless a default query function has been defined.\n *\n * The prefetch is skipped if the query already has any cached state — including a `pending`/`error` state left\n * over from a previous attempt — so calling this on every render is cheap and won't refetch data that's\n * already there or already in flight.\n *\n * @param options - The {@link UsePrefetchQueryOptions} to use — everything you can pass to `queryClient.query`.\n * @param queryClient - Use this to use a custom `QueryClient`. Otherwise, the one from the nearest context will\n * be used.\n * @returns `void` — nothing is returned.\n *\n * @example\n * ```tsx\n * import { Suspense } from 'react'\n * import { usePrefetchQuery } from '@tanstack/react-query'\n *\n * function App() {\n * // Fire the prefetch during render, before the suspense boundary below.\n * usePrefetchQuery({\n * queryKey: ['posts'],\n * queryFn: fetchPosts,\n * })\n *\n * return (\n * <Suspense fallback={<h1>Loading posts...</h1>}>\n * <Posts />\n * </Suspense>\n * )\n * }\n * ```\n */\nexport function usePrefetchQuery<\n TQueryFnData = unknown,\n TError = DefaultError,\n TData = TQueryFnData,\n TQueryData = TQueryFnData,\n TQueryKey extends QueryKey = QueryKey,\n>(\n options: UsePrefetchQueryOptions<\n TQueryFnData,\n TError,\n TData,\n TQueryData,\n TQueryKey\n >,\n queryClient?: QueryClient,\n): void {\n const client = useQueryClient(queryClient)\n\n if (!client.getQueryState(options.queryKey)) {\n void client.query(options).catch(noop)\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAyCA,SAAgB,iBAOd,SAOA,aACM;CACN,MAAM,SAAS,eAAe,WAAW;CAEzC,IAAI,CAAC,OAAO,cAAc,QAAQ,QAAQ,GACxC,OAAY,MAAM,OAAO,CAAC,CAAC,MAAM,IAAI;AAEzC"}
@@ -10,6 +10,136 @@ let react = require("react");
10
10
  react = require_rolldown_runtime.__toESM(react, 1);
11
11
  let _tanstack_query_core = require("@tanstack/query-core");
12
12
  //#region src/useQueries.ts
13
+ /**
14
+ * The `useQueries` hook can be used to fetch a variable number of queries.
15
+ *
16
+ * The `queries` key accepts an array with query option objects mostly identical to `useQuery` — the top-level
17
+ * `subscribed` option isn't accepted per query (see `placeholderData` below for another difference). A custom
18
+ * `QueryClient` is supplied once, as `useQueries`' own top-level second argument, rather than per query.
19
+ *
20
+ * Having the same query key more than once in the array of query objects may cause some data to be shared
21
+ * between queries. To avoid this, consider de-duplicating the queries and map the results back to the desired
22
+ * structure.
23
+ *
24
+ * The `combine` option can be used to combine the results of the queries into a single value. The result will
25
+ * be structurally shared to be as referentially stable as possible.
26
+ *
27
+ * @remarks The `combine` function only re-runs if it changed referentially, or if any of the query results
28
+ * changed. An inlined `combine` function, as shown in the example below, therefore runs on every render — wrap
29
+ * it in `useCallback`, or extract it to a stable function reference if it doesn't have any dependencies, to
30
+ * avoid that.
31
+ *
32
+ * Unlike `useQuery`, `useQueries` cannot infer the `data` argument of an _inline_ `select` from its sibling
33
+ * `queryFn`. Because `useQueries` infers the type of the whole `queries` array at once, the `select` parameter
34
+ * of a query object written inline cannot be contextually typed from that same object's `queryFn`, so it falls
35
+ * back to `unknown` — a [known TypeScript limitation](https://github.com/TanStack/query/issues/6556). Annotate
36
+ * the `select` parameter explicitly, or define the query with {@link queryOptions}, which resolves its types in
37
+ * a single object _before_ it reaches `useQueries`, to work around this — see the example below. The same
38
+ * limitation applies to {@link useSuspenseQueries}.
39
+ *
40
+ * `placeholderData` is supported here too, but unlike `useQuery`, it doesn't receive information from
41
+ * previously rendered queries, because the number of queries can differ between renders.
42
+ * @param queryClient - Use this to provide a custom `QueryClient`. Otherwise, the one from the nearest context
43
+ * will be used.
44
+ * @returns The combined result. Without `combine`, this is an array with all the query results, in the same
45
+ * order as the input. When `combine` is provided, this is the value returned by `combine` instead.
46
+ *
47
+ * @example
48
+ * ```tsx
49
+ * import { useQueries } from '@tanstack/react-query'
50
+ *
51
+ * function Posts({ ids }: { ids: Array<number> }) {
52
+ * const postQueries = useQueries({
53
+ * queries: ids.map((id) => ({
54
+ * queryKey: ['post', id],
55
+ * queryFn: () => fetchPost(id),
56
+ * staleTime: Infinity,
57
+ * })),
58
+ * })
59
+ *
60
+ * return (
61
+ * <ul>
62
+ * {postQueries.map((query, index) => {
63
+ * if (query.isPending) return <li key={ids[index]}>Loading...</li>
64
+ * if (query.isError) return <li key={ids[index]}>Error: {query.error.message}</li>
65
+ * return <li key={ids[index]}>{query.data.title}</li>
66
+ * })}
67
+ * </ul>
68
+ * )
69
+ * }
70
+ * ```
71
+ *
72
+ * @example
73
+ * Combining results into a single value:
74
+ * ```tsx
75
+ * import { useQueries } from '@tanstack/react-query'
76
+ *
77
+ * function Posts({ ids }: { ids: Array<number> }) {
78
+ * const { data, isPending, isError } = useQueries({
79
+ * queries: ids.map((id) => ({
80
+ * queryKey: ['post', id],
81
+ * queryFn: () => fetchPost(id),
82
+ * })),
83
+ * combine: (postQueries) => {
84
+ * return {
85
+ * data: postQueries.map((query) => query.data),
86
+ * isPending: postQueries.some((query) => query.isPending),
87
+ * isError: postQueries.some((query) => query.isError),
88
+ * }
89
+ * },
90
+ * })
91
+ *
92
+ * if (isPending) return 'Loading...'
93
+ * if (isError) return 'Error loading posts'
94
+ *
95
+ * return (
96
+ * <ul>
97
+ * {data.map((post) => (
98
+ * <li key={post?.id}>{post?.title}</li>
99
+ * ))}
100
+ * </ul>
101
+ * )
102
+ * }
103
+ * ```
104
+ *
105
+ * @example
106
+ * Typing `select` via {@link queryOptions}. Note that spreading a `queryOptions` result and overriding
107
+ * `select` inline still falls back to `unknown` — wrap the spread in `queryOptions` again so the override is
108
+ * resolved before it reaches `useQueries`:
109
+ * ```tsx
110
+ * import { queryOptions, useQueries } from '@tanstack/react-query'
111
+ *
112
+ * const postOptions = (id: number) =>
113
+ * queryOptions({
114
+ * queryKey: ['post', id],
115
+ * queryFn: () => fetchPost(id),
116
+ * })
117
+ *
118
+ * function PostTitle({ id }: { id: number }) {
119
+ * const [{ data: broken }] = useQueries({
120
+ * queries: [
121
+ * {
122
+ * ...postOptions(id),
123
+ * // ❌ `data` is `unknown` here
124
+ * select: (data) => data.title,
125
+ * },
126
+ * ],
127
+ * })
128
+ *
129
+ * const [{ data: fixed }] = useQueries({
130
+ * queries: [
131
+ * queryOptions({
132
+ * ...postOptions(id),
133
+ * // ✅ `data` is `Post`
134
+ * select: (data) => data.title,
135
+ * }),
136
+ * ],
137
+ * })
138
+ *
139
+ * return <h1>{fixed}</h1>
140
+ * }
141
+ * ```
142
+ */
13
143
  function useQueries({ queries, ...options }, queryClient) {
14
144
  const client = require_QueryClientProvider.useQueryClient(queryClient);
15
145
  const isRestoring = require_IsRestoringProvider.useIsRestoring();