@tanstack/preact-query 5.102.3 → 5.102.5

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 (296) hide show
  1. package/build/legacy/HydrationBoundary.cjs +43 -0
  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 +43 -0
  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 +77 -0
  26. package/build/legacy/QueryErrorResetBoundary.cjs.map +1 -1
  27. package/build/legacy/QueryErrorResetBoundary.d.cts +108 -0
  28. package/build/legacy/QueryErrorResetBoundary.d.cts.map +1 -1
  29. package/build/legacy/QueryErrorResetBoundary.d.ts +108 -0
  30. package/build/legacy/QueryErrorResetBoundary.d.ts.map +1 -1
  31. package/build/legacy/QueryErrorResetBoundary.js +77 -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 +187 -0
  35. package/build/legacy/infiniteQueryOptions.d.cts.map +1 -1
  36. package/build/legacy/infiniteQueryOptions.d.ts +187 -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 +68 -0
  41. package/build/legacy/mutationOptions.d.cts.map +1 -1
  42. package/build/legacy/mutationOptions.d.ts +68 -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 +198 -0
  47. package/build/legacy/queryOptions.d.cts.map +1 -1
  48. package/build/legacy/queryOptions.d.ts +198 -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 +120 -0
  59. package/build/legacy/useInfiniteQuery.d.cts.map +1 -1
  60. package/build/legacy/useInfiniteQuery.d.ts +120 -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 +34 -0
  64. package/build/legacy/useIsFetching.cjs.map +1 -1
  65. package/build/legacy/useIsFetching.d.cts +34 -0
  66. package/build/legacy/useIsFetching.d.cts.map +1 -1
  67. package/build/legacy/useIsFetching.d.ts +34 -0
  68. package/build/legacy/useIsFetching.d.ts.map +1 -1
  69. package/build/legacy/useIsFetching.js +34 -0
  70. package/build/legacy/useIsFetching.js.map +1 -1
  71. package/build/legacy/useMutation.cjs +170 -0
  72. package/build/legacy/useMutation.cjs.map +1 -1
  73. package/build/legacy/useMutation.d.cts +170 -0
  74. package/build/legacy/useMutation.d.cts.map +1 -1
  75. package/build/legacy/useMutation.d.ts +170 -0
  76. package/build/legacy/useMutation.d.ts.map +1 -1
  77. package/build/legacy/useMutation.js +170 -0
  78. package/build/legacy/useMutation.js.map +1 -1
  79. package/build/legacy/useMutationState.cjs +74 -0
  80. package/build/legacy/useMutationState.cjs.map +1 -1
  81. package/build/legacy/useMutationState.d.cts +74 -0
  82. package/build/legacy/useMutationState.d.cts.map +1 -1
  83. package/build/legacy/useMutationState.d.ts +74 -0
  84. package/build/legacy/useMutationState.d.ts.map +1 -1
  85. package/build/legacy/useMutationState.js +74 -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 +50 -0
  104. package/build/legacy/useQueries.cjs.map +1 -1
  105. package/build/legacy/useQueries.d.cts +85 -2
  106. package/build/legacy/useQueries.d.cts.map +1 -1
  107. package/build/legacy/useQueries.d.ts +85 -2
  108. package/build/legacy/useQueries.d.ts.map +1 -1
  109. package/build/legacy/useQueries.js +50 -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 +186 -0
  113. package/build/legacy/useQuery.d.cts.map +1 -1
  114. package/build/legacy/useQuery.d.ts +186 -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 +56 -0
  118. package/build/legacy/useSuspenseInfiniteQuery.cjs.map +1 -1
  119. package/build/legacy/useSuspenseInfiniteQuery.d.cts +56 -0
  120. package/build/legacy/useSuspenseInfiniteQuery.d.cts.map +1 -1
  121. package/build/legacy/useSuspenseInfiniteQuery.d.ts +56 -0
  122. package/build/legacy/useSuspenseInfiniteQuery.d.ts.map +1 -1
  123. package/build/legacy/useSuspenseInfiniteQuery.js +56 -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 +196 -2
  127. package/build/legacy/useSuspenseQueries.d.cts.map +1 -1
  128. package/build/legacy/useSuspenseQueries.d.ts +196 -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 +47 -0
  132. package/build/legacy/useSuspenseQuery.cjs.map +1 -1
  133. package/build/legacy/useSuspenseQuery.d.cts +47 -0
  134. package/build/legacy/useSuspenseQuery.d.cts.map +1 -1
  135. package/build/legacy/useSuspenseQuery.d.ts +47 -0
  136. package/build/legacy/useSuspenseQuery.d.ts.map +1 -1
  137. package/build/legacy/useSuspenseQuery.js +47 -0
  138. package/build/legacy/useSuspenseQuery.js.map +1 -1
  139. package/build/modern/HydrationBoundary.cjs +43 -0
  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 +43 -0
  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 +77 -0
  164. package/build/modern/QueryErrorResetBoundary.cjs.map +1 -1
  165. package/build/modern/QueryErrorResetBoundary.d.cts +108 -0
  166. package/build/modern/QueryErrorResetBoundary.d.cts.map +1 -1
  167. package/build/modern/QueryErrorResetBoundary.d.ts +108 -0
  168. package/build/modern/QueryErrorResetBoundary.d.ts.map +1 -1
  169. package/build/modern/QueryErrorResetBoundary.js +77 -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 +187 -0
  173. package/build/modern/infiniteQueryOptions.d.cts.map +1 -1
  174. package/build/modern/infiniteQueryOptions.d.ts +187 -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 +68 -0
  179. package/build/modern/mutationOptions.d.cts.map +1 -1
  180. package/build/modern/mutationOptions.d.ts +68 -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 +198 -0
  185. package/build/modern/queryOptions.d.cts.map +1 -1
  186. package/build/modern/queryOptions.d.ts +198 -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 +120 -0
  197. package/build/modern/useInfiniteQuery.d.cts.map +1 -1
  198. package/build/modern/useInfiniteQuery.d.ts +120 -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 +34 -0
  202. package/build/modern/useIsFetching.cjs.map +1 -1
  203. package/build/modern/useIsFetching.d.cts +34 -0
  204. package/build/modern/useIsFetching.d.cts.map +1 -1
  205. package/build/modern/useIsFetching.d.ts +34 -0
  206. package/build/modern/useIsFetching.d.ts.map +1 -1
  207. package/build/modern/useIsFetching.js +34 -0
  208. package/build/modern/useIsFetching.js.map +1 -1
  209. package/build/modern/useMutation.cjs +170 -0
  210. package/build/modern/useMutation.cjs.map +1 -1
  211. package/build/modern/useMutation.d.cts +170 -0
  212. package/build/modern/useMutation.d.cts.map +1 -1
  213. package/build/modern/useMutation.d.ts +170 -0
  214. package/build/modern/useMutation.d.ts.map +1 -1
  215. package/build/modern/useMutation.js +170 -0
  216. package/build/modern/useMutation.js.map +1 -1
  217. package/build/modern/useMutationState.cjs +74 -0
  218. package/build/modern/useMutationState.cjs.map +1 -1
  219. package/build/modern/useMutationState.d.cts +74 -0
  220. package/build/modern/useMutationState.d.cts.map +1 -1
  221. package/build/modern/useMutationState.d.ts +74 -0
  222. package/build/modern/useMutationState.d.ts.map +1 -1
  223. package/build/modern/useMutationState.js +74 -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 +50 -0
  242. package/build/modern/useQueries.cjs.map +1 -1
  243. package/build/modern/useQueries.d.cts +85 -2
  244. package/build/modern/useQueries.d.cts.map +1 -1
  245. package/build/modern/useQueries.d.ts +85 -2
  246. package/build/modern/useQueries.d.ts.map +1 -1
  247. package/build/modern/useQueries.js +50 -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 +186 -0
  251. package/build/modern/useQuery.d.cts.map +1 -1
  252. package/build/modern/useQuery.d.ts +186 -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 +56 -0
  256. package/build/modern/useSuspenseInfiniteQuery.cjs.map +1 -1
  257. package/build/modern/useSuspenseInfiniteQuery.d.cts +56 -0
  258. package/build/modern/useSuspenseInfiniteQuery.d.cts.map +1 -1
  259. package/build/modern/useSuspenseInfiniteQuery.d.ts +56 -0
  260. package/build/modern/useSuspenseInfiniteQuery.d.ts.map +1 -1
  261. package/build/modern/useSuspenseInfiniteQuery.js +56 -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 +196 -2
  265. package/build/modern/useSuspenseQueries.d.cts.map +1 -1
  266. package/build/modern/useSuspenseQueries.d.ts +196 -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 +47 -0
  270. package/build/modern/useSuspenseQuery.cjs.map +1 -1
  271. package/build/modern/useSuspenseQuery.d.cts +47 -0
  272. package/build/modern/useSuspenseQuery.d.cts.map +1 -1
  273. package/build/modern/useSuspenseQuery.d.ts +47 -0
  274. package/build/modern/useSuspenseQuery.d.ts.map +1 -1
  275. package/build/modern/useSuspenseQuery.js +47 -0
  276. package/build/modern/useSuspenseQuery.js.map +1 -1
  277. package/package.json +3 -3
  278. package/src/HydrationBoundary.tsx +61 -0
  279. package/src/IsRestoringProvider.ts +12 -0
  280. package/src/QueryClientProvider.tsx +41 -0
  281. package/src/QueryErrorResetBoundary.tsx +111 -0
  282. package/src/infiniteQueryOptions.ts +187 -0
  283. package/src/mutationOptions.ts +68 -0
  284. package/src/queryOptions.ts +198 -0
  285. package/src/types.ts +228 -2
  286. package/src/useInfiniteQuery.ts +120 -0
  287. package/src/useIsFetching.ts +34 -0
  288. package/src/useMutation.ts +170 -0
  289. package/src/useMutationState.ts +74 -0
  290. package/src/usePrefetchInfiniteQuery.tsx +44 -0
  291. package/src/usePrefetchQuery.tsx +35 -0
  292. package/src/useQueries.ts +85 -2
  293. package/src/useQuery.ts +186 -0
  294. package/src/useSuspenseInfiniteQuery.ts +56 -0
  295. package/src/useSuspenseQueries.ts +196 -2
  296. package/src/useSuspenseQuery.ts +47 -0
@@ -17,6 +17,176 @@ import { useSyncExternalStore } from './utils'
17
17
 
18
18
  // HOOK
19
19
 
20
+ /**
21
+ * Unlike queries, mutations are typically used to create/update/delete data or perform server side-effects.
22
+ * `useMutation` is the hook for that.
23
+ *
24
+ * @see {@link mutationOptions} to share these options across multiple `useMutation` call sites.
25
+ * @param options - The {@link UseMutationOptions} to use — everything you can pass to `useMutation`.
26
+ * @param queryClient - Use this to use a custom `QueryClient`. Otherwise, the one from the nearest context will
27
+ * be used.
28
+ * @returns `mutate`/`mutateAsync` also accept per-call `onSuccess`/`onError`/`onSettled` callbacks as a second
29
+ * argument, useful for triggering call-site side effects (e.g. navigation) without coupling them to the shared
30
+ * mutation definition. If you make multiple requests, `onSuccess` will fire only after the latest call you've
31
+ * made.
32
+ *
33
+ * @example
34
+ * ```tsx
35
+ * import { useMutation, useQueryClient } from '@tanstack/preact-query'
36
+ *
37
+ * function AddTodo() {
38
+ * const queryClient = useQueryClient()
39
+ *
40
+ * const addMutation = useMutation({
41
+ * mutationFn: addTodo,
42
+ * onSuccess: () => queryClient.invalidateQueries({ queryKey: ['todos'] }),
43
+ * })
44
+ *
45
+ * return (
46
+ * <button
47
+ * onClick={() =>
48
+ * addMutation.mutate('Item', {
49
+ * onError: (error) => console.error('Failed to add item:', error),
50
+ * })
51
+ * }
52
+ * >
53
+ * Add
54
+ * </button>
55
+ * )
56
+ * }
57
+ * ```
58
+ *
59
+ * @example
60
+ * Rendering the mutation's own state, rather than just firing it off:
61
+ * ```tsx
62
+ * import { useMutation, useQueryClient } from '@tanstack/preact-query'
63
+ *
64
+ * function AddTodo() {
65
+ * const queryClient = useQueryClient()
66
+ *
67
+ * const addMutation = useMutation({
68
+ * mutationFn: addTodo,
69
+ * onSuccess: () => queryClient.invalidateQueries({ queryKey: ['todos'] }),
70
+ * })
71
+ *
72
+ * return (
73
+ * <div>
74
+ * {addMutation.isPending ? (
75
+ * 'Adding todo...'
76
+ * ) : (
77
+ * <>
78
+ * {addMutation.isError ? (
79
+ * <div>An error occurred: {addMutation.error.message}</div>
80
+ * ) : null}
81
+ * <button onClick={() => addMutation.mutate('Item')}>Add</button>
82
+ * </>
83
+ * )}
84
+ * </div>
85
+ * )
86
+ * }
87
+ * ```
88
+ *
89
+ * @example
90
+ * Optimistic update via `onMutate`, rolling back on `onError`:
91
+ * ```tsx
92
+ * import { useMutation, useQueryClient } from '@tanstack/preact-query'
93
+ *
94
+ * function AddTodo() {
95
+ * const queryClient = useQueryClient()
96
+ *
97
+ * const addMutation = useMutation({
98
+ * mutationFn: addTodo,
99
+ * onMutate: async (newTodo) => {
100
+ * await queryClient.cancelQueries({ queryKey: ['todos'] })
101
+ * const previousTodos = queryClient.getQueryData<Array<string>>(['todos'])
102
+ *
103
+ * queryClient.setQueryData<Array<string>>(['todos'], (old) => [
104
+ * ...(old ?? []),
105
+ * newTodo,
106
+ * ])
107
+ *
108
+ * // Passed to `onError` as `context` if the mutation fails.
109
+ * return { previousTodos }
110
+ * },
111
+ * onError: (_err, _newTodo, context) => {
112
+ * queryClient.setQueryData(['todos'], context?.previousTodos)
113
+ * },
114
+ * onSettled: () => {
115
+ * queryClient.invalidateQueries({ queryKey: ['todos'] })
116
+ * },
117
+ * })
118
+ *
119
+ * return (
120
+ * <button onClick={() => addMutation.mutate('Item')}>Add</button>
121
+ * )
122
+ * }
123
+ * ```
124
+ *
125
+ * @example
126
+ * Callbacks passed per call to `mutate` only fire for the last call — `mutateAsync` gives you a
127
+ * promise per call instead, so you can wait for all of them:
128
+ * ```tsx
129
+ * import { useMutation, useQueryClient } from '@tanstack/preact-query'
130
+ *
131
+ * function AddTodos() {
132
+ * const queryClient = useQueryClient()
133
+ *
134
+ * const addMutation = useMutation({
135
+ * mutationFn: addTodo,
136
+ * onSuccess: () => queryClient.invalidateQueries({ queryKey: ['todos'] }),
137
+ * })
138
+ *
139
+ * async function handleAddAll(todos: Array<string>) {
140
+ * try {
141
+ * await Promise.all(todos.map((todo) => addMutation.mutateAsync(todo)))
142
+ * } catch (error) {
143
+ * console.error('Failed to add todos:', error)
144
+ * }
145
+ * }
146
+ *
147
+ * return (
148
+ * <button onClick={() => handleAddAll(['Todo 1', 'Todo 2', 'Todo 3'])}>
149
+ * Add all
150
+ * </button>
151
+ * )
152
+ * }
153
+ * ```
154
+ *
155
+ * @example
156
+ * If some of the mutations above can fail independently of the others, and you want to know which ones
157
+ * did — rather than losing that information the moment the first one rejects — swap `Promise.all` for
158
+ * `Promise.allSettled`:
159
+ * ```tsx
160
+ * import { useMutation, useQueryClient } from '@tanstack/preact-query'
161
+ *
162
+ * function AddTodos() {
163
+ * const queryClient = useQueryClient()
164
+ *
165
+ * const addMutation = useMutation({
166
+ * mutationFn: addTodo,
167
+ * onSuccess: () => queryClient.invalidateQueries({ queryKey: ['todos'] }),
168
+ * })
169
+ *
170
+ * async function handleAddAll(todos: Array<string>) {
171
+ * const results = await Promise.allSettled(
172
+ * todos.map((todo) => addMutation.mutateAsync(todo)),
173
+ * )
174
+ *
175
+ * results.forEach((result, index) => {
176
+ * if (result.status === 'rejected') {
177
+ * console.error(`Failed to add "${todos[index]}":`, result.reason)
178
+ * }
179
+ * })
180
+ * }
181
+ *
182
+ * return (
183
+ * <button onClick={() => handleAddAll(['Todo 1', 'Todo 2', 'Todo 3'])}>
184
+ * Add all
185
+ * </button>
186
+ * )
187
+ * }
188
+ * ```
189
+ */
20
190
  export function useMutation<
21
191
  TData = unknown,
22
192
  TError = DefaultError,
@@ -11,6 +11,25 @@ import { useCallback, useEffect, useRef } from 'preact/hooks'
11
11
  import { useQueryClient } from './QueryClientProvider'
12
12
  import { useSyncExternalStore } from './utils'
13
13
 
14
+ /**
15
+ * `useIsMutating` is an optional hook that returns the `number` of mutations that your application is fetching
16
+ * (useful for app-wide loading indicators).
17
+ *
18
+ * @param filters - The {@link MutationFilters} to narrow down the matched mutations.
19
+ * @param queryClient - Use this to use a custom `QueryClient`. Otherwise, the one from the nearest context will
20
+ * be used.
21
+ * @returns Will be the `number` of the mutations that your application is currently fetching.
22
+ *
23
+ * @example
24
+ * ```tsx
25
+ * import { useIsMutating } from '@tanstack/preact-query'
26
+ *
27
+ * // How many mutations are fetching?
28
+ * const isMutating = useIsMutating()
29
+ * // How many mutations matching the posts prefix are fetching?
30
+ * const isMutatingPosts = useIsMutating({ mutationKey: ['posts'] })
31
+ * ```
32
+ */
14
33
  export function useIsMutating(
15
34
  filters?: MutationFilters,
16
35
  queryClient?: QueryClient,
@@ -60,6 +79,61 @@ function getResult<
60
79
  )
61
80
  }
62
81
 
82
+ /**
83
+ * `useMutationState` is a hook that gives you access to all mutations in the `MutationCache`. You can pass
84
+ * `filters` ({@link MutationFilters}) to narrow down your mutations, and `select` to transform the mutation
85
+ * state.
86
+ *
87
+ * @param options - The `filters` to narrow down matched mutations, and an optional `select` to transform the
88
+ * mutation state.
89
+ * @param queryClient - Use this to use a custom `QueryClient`. Otherwise, the one from the nearest context will
90
+ * be used.
91
+ * @returns Will be an Array of whatever `select` returns for each matching mutation.
92
+ *
93
+ * @example
94
+ * Get all variables of all running mutations:
95
+ * ```tsx
96
+ * import { useMutationState } from '@tanstack/preact-query'
97
+ *
98
+ * const variables = useMutationState({
99
+ * filters: { status: 'pending' },
100
+ * select: (mutation) => mutation.state.variables,
101
+ * })
102
+ * ```
103
+ *
104
+ * @example
105
+ * Get all data for specific mutations via the `mutationKey`:
106
+ * ```tsx
107
+ * import { useMutation, useMutationState } from '@tanstack/preact-query'
108
+ *
109
+ * const mutationKey = ['posts']
110
+ *
111
+ * // Some mutation that we want to get the state for
112
+ * const mutation = useMutation({
113
+ * mutationKey,
114
+ * mutationFn: createPosts,
115
+ * })
116
+ *
117
+ * const data = useMutationState({
118
+ * // this mutation key needs to match the mutation key of the given mutation (see above)
119
+ * filters: { mutationKey },
120
+ * select: (mutation) => mutation.state.data,
121
+ * })
122
+ * ```
123
+ *
124
+ * @example
125
+ * Access the latest mutation data via the `mutationKey`. Each invocation of `mutate` adds a new entry to the
126
+ * mutation cache for `gcTime` milliseconds — check the last item that `useMutationState` returns to get the
127
+ * latest invocation:
128
+ * ```tsx
129
+ * const data = useMutationState({
130
+ * filters: { mutationKey: ['posts'] },
131
+ * select: (mutation) => mutation.state.data,
132
+ * })
133
+ *
134
+ * const latest = data[data.length - 1]
135
+ * ```
136
+ */
63
137
  export function useMutationState<
64
138
  TResult = MutationState,
65
139
  TMutation extends Mutation<any, any, any, any> =
@@ -4,6 +4,50 @@ import { useQueryClient } from './QueryClientProvider'
4
4
  import type { DefaultError, QueryClient, QueryKey } from '@tanstack/query-core'
5
5
  import type { UsePrefetchInfiniteQueryOptions } from './types'
6
6
 
7
+ /**
8
+ * `usePrefetchInfiniteQuery` does not return anything, it should be used just to fire a prefetch during render,
9
+ * before a suspense boundary that wraps a component that uses `useSuspenseInfiniteQuery`. You can pass
10
+ * everything to `usePrefetchInfiniteQuery` that you can pass to `queryClient.infiniteQuery`, though
11
+ * `queryKey`, `initialPageParam`, and `getNextPageParam` are always required, and `queryFn` is required unless
12
+ * a default query function has been defined.
13
+ *
14
+ * `getNextPageParam` receives both the last page of the infinite list of data and the full array of all pages,
15
+ * as well as pageParam information, and should return a single variable that will be passed to your query
16
+ * function as `context.pageParam`. Return `undefined` or `null` to indicate there is no next page available.
17
+ *
18
+ * The prefetch is skipped if the query already has any cached state — including a `pending`/`error` state left
19
+ * over from a previous attempt — so calling this on every render is cheap and won't refetch data that's
20
+ * already there or already in flight.
21
+ *
22
+ * @param options - The {@link UsePrefetchInfiniteQueryOptions} to use — everything you can pass to `queryClient.infiniteQuery`.
23
+ * @param queryClient - Use this to use a custom `QueryClient`. Otherwise, the one from the nearest context will
24
+ * be used.
25
+ * @returns `void` — nothing is returned.
26
+ *
27
+ * @example
28
+ * ```tsx
29
+ * import { Suspense } from 'preact/compat'
30
+ * import { infiniteQueryOptions, usePrefetchInfiniteQuery } from '@tanstack/preact-query'
31
+ *
32
+ * const projectsOptions = infiniteQueryOptions({
33
+ * queryKey: ['projects'],
34
+ * queryFn: ({ pageParam }) => fetchProjects(pageParam),
35
+ * initialPageParam: 0,
36
+ * getNextPageParam: (lastPage) => lastPage.nextId,
37
+ * })
38
+ *
39
+ * function App() {
40
+ * // Fire the prefetch during render, before the suspense boundary below.
41
+ * usePrefetchInfiniteQuery(projectsOptions)
42
+ *
43
+ * return (
44
+ * <Suspense fallback={<h1>Loading projects...</h1>}>
45
+ * <Projects />
46
+ * </Suspense>
47
+ * )
48
+ * }
49
+ * ```
50
+ */
7
51
  export function usePrefetchInfiniteQuery<
8
52
  TQueryFnData = unknown,
9
53
  TError = DefaultError,
@@ -4,6 +4,41 @@ import { useQueryClient } from './QueryClientProvider'
4
4
  import type { DefaultError, QueryClient, QueryKey } from '@tanstack/query-core'
5
5
  import type { UsePrefetchQueryOptions } from './types'
6
6
 
7
+ /**
8
+ * `usePrefetchQuery` does not return anything, it should be used just to fire a prefetch during render, before
9
+ * a suspense boundary that wraps a component that uses `useSuspenseQuery`. You can pass everything to
10
+ * `usePrefetchQuery` that you can pass to `queryClient.query`, though `queryKey` is always required, and
11
+ * `queryFn` is required unless a default query function has been defined.
12
+ *
13
+ * The prefetch is skipped if the query already has any cached state — including a `pending`/`error` state left
14
+ * over from a previous attempt — so calling this on every render is cheap and won't refetch data that's
15
+ * already there or already in flight.
16
+ *
17
+ * @param options - The {@link UsePrefetchQueryOptions} to use — everything you can pass to `queryClient.query`.
18
+ * @param queryClient - Use this to use a custom `QueryClient`. Otherwise, the one from the nearest context will
19
+ * be used.
20
+ * @returns `void` — nothing is returned.
21
+ *
22
+ * @example
23
+ * ```tsx
24
+ * import { Suspense } from 'preact/compat'
25
+ * import { usePrefetchQuery } from '@tanstack/preact-query'
26
+ *
27
+ * function App() {
28
+ * // Fire the prefetch during render, before the suspense boundary below.
29
+ * usePrefetchQuery({
30
+ * queryKey: ['posts'],
31
+ * queryFn: fetchPosts,
32
+ * })
33
+ *
34
+ * return (
35
+ * <Suspense fallback={<h1>Loading posts...</h1>}>
36
+ * <Posts />
37
+ * </Suspense>
38
+ * )
39
+ * }
40
+ * ```
41
+ */
7
42
  export function usePrefetchQuery<
8
43
  TQueryFnData = unknown,
9
44
  TError = DefaultError,
package/src/useQueries.ts CHANGED
@@ -142,7 +142,16 @@ type GetUseQueryResult<T> =
142
142
  UseQueryResult
143
143
 
144
144
  /**
145
- * QueriesOptions reducer recursively unwraps function arguments to infer/enforce type param
145
+ * The `queries` array accepted by `useQueries`. Recursively unwraps each tuple element so every entry's
146
+ * `queryFn`/`select`/`throwOnError` are inferred individually, up to 20 elements. An opaque array (e.g.
147
+ * `unknown[]`) is returned as-is; a non-tuple array of a known element type, or a tuple past 20 elements, falls
148
+ * back to a single homogeneous options type.
149
+ *
150
+ * @template T - The type of the `queries` array as written at the call site.
151
+ * @template TResults - The internal accumulator that this type builds during recursion. It is not meant
152
+ * to be set explicitly.
153
+ * @template TDepth - The internal recursion-depth counter, checked against the 20-element limit. It is not
154
+ * meant to be set explicitly.
146
155
  */
147
156
  export type QueriesOptions<
148
157
  T extends Array<any>,
@@ -184,7 +193,16 @@ export type QueriesOptions<
184
193
  Array<UseQueryOptionsForUseQueries>
185
194
 
186
195
  /**
187
- * QueriesResults reducer recursively maps type param to results
196
+ * The result type returned by `useQueries`, when no `combine` is provided. Mirrors {@link QueriesOptions}: each
197
+ * tuple element's result type is inferred individually, up to 20 elements. A non-tuple array is mapped
198
+ * per-element instead, still inferring each entry individually; only past 20 elements does this fall back to a
199
+ * single homogeneous {@link UseQueryResult} type.
200
+ *
201
+ * @template T - The type of the `queries` array, as inferred by {@link QueriesOptions}.
202
+ * @template TResults - The internal accumulator that this type builds during recursion. It is not meant
203
+ * to be set explicitly.
204
+ * @template TDepth - The internal recursion-depth counter, checked against the 20-element limit. It is not
205
+ * meant to be set explicitly.
188
206
  */
189
207
  export type QueriesResults<
190
208
  T extends Array<any>,
@@ -204,6 +222,56 @@ export type QueriesResults<
204
222
  >
205
223
  : { [K in keyof T]: GetUseQueryResult<T[K]> }
206
224
 
225
+ /**
226
+ * The `useQueries` hook can be used to fetch a variable number of queries.
227
+ *
228
+ * The `queries` key accepts an array with query option objects identical to `useQuery` (excluding the
229
+ * `queryClient` option - because the `QueryClient` can be passed in on the top level).
230
+ *
231
+ * Having the same query key more than once in the array of query objects may cause some data to be shared
232
+ * between queries. To avoid this, consider de-duplicating the queries and map the results back to the desired
233
+ * structure.
234
+ *
235
+ * The `combine` option can be used to combine the results of the queries into a single value. The result will
236
+ * be structurally shared to be as referentially stable as possible.
237
+ *
238
+ * @param queryClient - Use this to provide a custom `QueryClient`. Otherwise, the one from the nearest context
239
+ * will be used.
240
+ * @returns The combined result. Without `combine`, this is an array with all the query results, in the same
241
+ * order as the input. When `combine` is provided, this is the value returned by `combine` instead.
242
+ *
243
+ * @example
244
+ * ```tsx
245
+ * import { useQueries } from '@tanstack/preact-query'
246
+ *
247
+ * const ids = [1, 2, 3]
248
+ * const results = useQueries({
249
+ * queries: ids.map((id) => ({
250
+ * queryKey: ['post', id],
251
+ * queryFn: () => fetchPost(id),
252
+ * staleTime: Infinity,
253
+ * })),
254
+ * })
255
+ * ```
256
+ *
257
+ * @example
258
+ * Combining results into a single value:
259
+ * ```tsx
260
+ * const ids = [1, 2, 3]
261
+ * const combinedQueries = useQueries({
262
+ * queries: ids.map((id) => ({
263
+ * queryKey: ['post', id],
264
+ * queryFn: () => fetchPost(id),
265
+ * })),
266
+ * combine: (results) => {
267
+ * return {
268
+ * data: results.map((result) => result.data),
269
+ * pending: results.some((result) => result.isPending),
270
+ * }
271
+ * },
272
+ * })
273
+ * ```
274
+ */
207
275
  export function useQueries<
208
276
  T extends Array<any>,
209
277
  TCombinedResult = QueriesResults<T>,
@@ -212,10 +280,25 @@ export function useQueries<
212
280
  queries,
213
281
  ...options
214
282
  }: {
283
+ /**
284
+ * An array with query option objects, mostly identical to `useQuery` — except that `queryClient` and
285
+ * `subscribed` aren't accepted per-query (`subscribed` is a top-level option here instead), and
286
+ * `placeholderData` accepts a {@link QueriesPlaceholderDataFunction}, which is called with `previousData`
287
+ * and `previousQuery` always `undefined`, rather than `useQuery`'s placeholder function.
288
+ */
215
289
  queries:
216
290
  | readonly [...QueriesOptions<T>]
217
291
  | readonly [...{ [K in keyof T]: GetUseQueryOptionsForUseQueries<T[K]> }]
292
+ /**
293
+ * Use this to combine the results of the queries into a single value. The result will be structurally
294
+ * shared to be as referentially stable as possible.
295
+ */
218
296
  combine?: (result: QueriesResults<T>) => TCombinedResult
297
+ /**
298
+ * Set this to `false` to unsubscribe this observer from updates to the query cache.
299
+ *
300
+ * @defaultValue true
301
+ */
219
302
  subscribed?: boolean
220
303
  },
221
304
  queryClient?: QueryClient,
package/src/useQuery.ts CHANGED
@@ -12,6 +12,33 @@ import type {
12
12
  } from './types'
13
13
  import { useBaseQuery } from './useBaseQuery'
14
14
 
15
+ /**
16
+ * This overload is selected when `initialData` is set, so the resulting `data` is never `undefined`.
17
+ *
18
+ * @see {@link queryOptions} to share these options between `useQuery` and imperative APIs like `queryClient.query`.
19
+ * @param options - The {@link DefinedInitialDataOptions} to use — everything you can pass to `useQuery`, with `initialData` set.
20
+ * @param queryClient - Use this to use a custom `QueryClient`. Otherwise, the one from the nearest context will
21
+ * be used.
22
+ * @returns The current query result, typed so that `status` is `success` — or `error` if a fetch attempt
23
+ * fails while keeping the existing data (`status` never resolves to `pending` in this overload's type,
24
+ * since `initialData` guarantees data upfront). `isSuccess`/`isError` are derived booleans for convenience.
25
+ *
26
+ * @example
27
+ * ```tsx
28
+ * import { useQuery } from '@tanstack/preact-query'
29
+ *
30
+ * function Posts() {
31
+ * // `data` is `Post[]`, never `undefined`, thanks to `initialData`.
32
+ * const { data } = useQuery({
33
+ * queryKey: ['posts'],
34
+ * queryFn: fetchPosts,
35
+ * initialData: [],
36
+ * })
37
+ *
38
+ * return <>{data.map((post) => <p key={post.id}>{post.title}</p>)}</>
39
+ * }
40
+ * ```
41
+ */
15
42
  export function useQuery<
16
43
  TQueryFnData = unknown,
17
44
  TError = DefaultError,
@@ -22,6 +49,59 @@ export function useQuery<
22
49
  queryClient?: QueryClient,
23
50
  ): DefinedUseQueryResult<TData, TError>
24
51
 
52
+ /**
53
+ * @see {@link queryOptions} to share these options between `useQuery` and imperative APIs like `queryClient.query`.
54
+ * @param options - The {@link UndefinedInitialDataOptions} to use — everything you can pass to `useQuery`.
55
+ * @param queryClient - Use this to use a custom `QueryClient`. Otherwise, the one from the nearest context will
56
+ * be used.
57
+ * @returns The current query result. `status` is `pending` if there is no cached data and no query attempt
58
+ * has finished yet, `error` if the query attempt resulted in an error, or `success` if the query has data to
59
+ * display. `isPending`/`isSuccess`/`isError` are derived booleans for convenience.
60
+ *
61
+ * @example
62
+ * ```tsx
63
+ * import { queryOptions, useQuery } from '@tanstack/preact-query'
64
+ *
65
+ * const postsOptions = queryOptions({
66
+ * queryKey: ['posts'],
67
+ * queryFn: fetchPosts,
68
+ * })
69
+ *
70
+ * function Posts() {
71
+ * const { status, data, error, isFetching } = useQuery(postsOptions)
72
+ *
73
+ * if (status === 'pending') return 'Loading...'
74
+ * if (status === 'error') return <span>Error: {error.message}</span>
75
+ *
76
+ * return (
77
+ * <div>
78
+ * {data.map((post) => (
79
+ * <p key={post.id}>{post.title}</p>
80
+ * ))}
81
+ * <div>{isFetching ? 'Background Updating...' : ' '}</div>
82
+ * </div>
83
+ * )
84
+ * }
85
+ * ```
86
+ *
87
+ * @example
88
+ * The same query, checking `isPending`/`isError` instead of `status` — pick whichever reads better to you:
89
+ * ```tsx
90
+ * import { useQuery } from '@tanstack/preact-query'
91
+ *
92
+ * function Posts() {
93
+ * const { isPending, isError, data, error } = useQuery({
94
+ * queryKey: ['posts'],
95
+ * queryFn: fetchPosts,
96
+ * })
97
+ *
98
+ * if (isPending) return 'Loading...'
99
+ * if (isError) return <span>Error: {error.message}</span>
100
+ *
101
+ * return <>{data.map((post) => <p key={post.id}>{post.title}</p>)}</>
102
+ * }
103
+ * ```
104
+ */
25
105
  export function useQuery<
26
106
  TQueryFnData = unknown,
27
107
  TError = DefaultError,
@@ -32,6 +112,112 @@ export function useQuery<
32
112
  queryClient?: QueryClient,
33
113
  ): UseQueryResult<TData, TError>
34
114
 
115
+ /**
116
+ * @see {@link queryOptions} to share these options between `useQuery` and imperative APIs like `queryClient.query`.
117
+ * @param options - The {@link UseQueryOptions} to use — everything you can pass to `useQuery`.
118
+ * @param queryClient - Use this to use a custom `QueryClient`. Otherwise, the one from the nearest context will
119
+ * be used.
120
+ * @returns The current query result. `status` is `pending` if there is no cached data and no query attempt
121
+ * has finished yet, `error` if the query attempt resulted in an error, or `success` if the query has data to
122
+ * display. `isPending`/`isSuccess`/`isError` are derived booleans for convenience.
123
+ *
124
+ * @example
125
+ * ```tsx
126
+ * import { queryOptions, useQuery } from '@tanstack/preact-query'
127
+ *
128
+ * const postsOptions = queryOptions({
129
+ * queryKey: ['posts'],
130
+ * queryFn: fetchPosts,
131
+ * })
132
+ *
133
+ * function Posts() {
134
+ * const { status, data, error, isFetching } = useQuery(postsOptions)
135
+ *
136
+ * if (status === 'pending') return 'Loading...'
137
+ * if (status === 'error') return <span>Error: {error.message}</span>
138
+ *
139
+ * return (
140
+ * <div>
141
+ * {data.map((post) => (
142
+ * <p key={post.id}>{post.title}</p>
143
+ * ))}
144
+ * <div>{isFetching ? 'Background Updating...' : ' '}</div>
145
+ * </div>
146
+ * )
147
+ * }
148
+ * ```
149
+ *
150
+ * @example
151
+ * A dependent query, only enabled once `postId` is set — use `isLoading`, not `isPending`, so the
152
+ * loading state doesn't show while the query is disabled:
153
+ * ```tsx
154
+ * import { useQuery } from '@tanstack/preact-query'
155
+ *
156
+ * function Post({ postId }: { postId: number | undefined }) {
157
+ * const { data, isLoading, isError, error } = useQuery({
158
+ * queryKey: ['post', postId],
159
+ * queryFn: () => fetchPost(postId!),
160
+ * enabled: postId != null,
161
+ * })
162
+ *
163
+ * if (postId == null) return 'Select a post'
164
+ * if (isLoading) return 'Loading...'
165
+ * if (isError) return <span>Error: {error.message}</span>
166
+ *
167
+ * return <h1>{data?.title}</h1>
168
+ * }
169
+ * ```
170
+ *
171
+ * @example
172
+ * Seeding a detail query from an already-cached list, to skip the loading state:
173
+ * ```tsx
174
+ * import { useQuery, useQueryClient } from '@tanstack/preact-query'
175
+ *
176
+ * function Post({ postId }: { postId: number }) {
177
+ * const queryClient = useQueryClient()
178
+ *
179
+ * const { data } = useQuery({
180
+ * queryKey: ['post', postId],
181
+ * queryFn: () => fetchPost(postId),
182
+ * initialData: () =>
183
+ * queryClient
184
+ * .getQueryData<Array<Post>>(['posts'])
185
+ * ?.find((post) => post.id === postId),
186
+ * })
187
+ *
188
+ * return <h1>{data?.title}</h1>
189
+ * }
190
+ * ```
191
+ *
192
+ * @example
193
+ * Paginated data, keeping the previous page's data visible while the next page loads:
194
+ * ```tsx
195
+ * import { keepPreviousData, useQuery } from '@tanstack/preact-query'
196
+ * import { useState } from 'preact/hooks'
197
+ *
198
+ * function Posts() {
199
+ * const [page, setPage] = useState(0)
200
+ *
201
+ * const { data, isPlaceholderData } = useQuery({
202
+ * queryKey: ['posts', page],
203
+ * queryFn: () => fetchPosts(page),
204
+ * placeholderData: keepPreviousData,
205
+ * })
206
+ *
207
+ * return (
208
+ * <div>
209
+ * {data?.map((post) => <p key={post.id}>{post.title}</p>)}
210
+ * <button
211
+ * disabled={isPlaceholderData}
212
+ * onClick={() => setPage((old) => old + 1)}
213
+ * >
214
+ * Next Page
215
+ * </button>
216
+ * </div>
217
+ * )
218
+ * }
219
+ * ```
220
+ */
35
221
  export function useQuery<
36
222
  TQueryFnData = unknown,
37
223
  TError = DefaultError,