@tanstack/preact-query 5.102.2 → 5.102.4

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 (305) 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 +75 -0
  26. package/build/legacy/QueryErrorResetBoundary.cjs.map +1 -1
  27. package/build/legacy/QueryErrorResetBoundary.d.cts +106 -0
  28. package/build/legacy/QueryErrorResetBoundary.d.cts.map +1 -1
  29. package/build/legacy/QueryErrorResetBoundary.d.ts +106 -0
  30. package/build/legacy/QueryErrorResetBoundary.d.ts.map +1 -1
  31. package/build/legacy/QueryErrorResetBoundary.js +75 -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 +116 -0
  59. package/build/legacy/useInfiniteQuery.d.cts.map +1 -1
  60. package/build/legacy/useInfiniteQuery.d.ts +116 -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 +20 -0
  64. package/build/legacy/useIsFetching.cjs.map +1 -1
  65. package/build/legacy/useIsFetching.d.cts +20 -0
  66. package/build/legacy/useIsFetching.d.cts.map +1 -1
  67. package/build/legacy/useIsFetching.d.ts +20 -0
  68. package/build/legacy/useIsFetching.d.ts.map +1 -1
  69. package/build/legacy/useIsFetching.js +20 -0
  70. package/build/legacy/useIsFetching.js.map +1 -1
  71. package/build/legacy/useMutation.cjs +67 -0
  72. package/build/legacy/useMutation.cjs.map +1 -1
  73. package/build/legacy/useMutation.d.cts +67 -0
  74. package/build/legacy/useMutation.d.cts.map +1 -1
  75. package/build/legacy/useMutation.d.ts +67 -0
  76. package/build/legacy/useMutation.d.ts.map +1 -1
  77. package/build/legacy/useMutation.js +67 -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 +36 -1
  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 +36 -1
  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 +134 -0
  113. package/build/legacy/useQuery.d.cts.map +1 -1
  114. package/build/legacy/useQuery.d.ts +134 -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 +48 -0
  118. package/build/legacy/useSuspenseInfiniteQuery.cjs.map +1 -1
  119. package/build/legacy/useSuspenseInfiniteQuery.d.cts +48 -0
  120. package/build/legacy/useSuspenseInfiniteQuery.d.cts.map +1 -1
  121. package/build/legacy/useSuspenseInfiniteQuery.d.ts +48 -0
  122. package/build/legacy/useSuspenseInfiniteQuery.d.ts.map +1 -1
  123. package/build/legacy/useSuspenseInfiniteQuery.js +48 -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 +128 -2
  127. package/build/legacy/useSuspenseQueries.d.cts.map +1 -1
  128. package/build/legacy/useSuspenseQueries.d.ts +128 -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 +43 -0
  132. package/build/legacy/useSuspenseQuery.cjs.map +1 -1
  133. package/build/legacy/useSuspenseQuery.d.cts +43 -0
  134. package/build/legacy/useSuspenseQuery.d.cts.map +1 -1
  135. package/build/legacy/useSuspenseQuery.d.ts +43 -0
  136. package/build/legacy/useSuspenseQuery.d.ts.map +1 -1
  137. package/build/legacy/useSuspenseQuery.js +43 -0
  138. package/build/legacy/useSuspenseQuery.js.map +1 -1
  139. package/build/legacy/utils.cjs.map +1 -1
  140. package/build/legacy/utils.d.cts.map +1 -1
  141. package/build/legacy/utils.d.ts.map +1 -1
  142. package/build/legacy/utils.js.map +1 -1
  143. package/build/modern/HydrationBoundary.cjs +43 -0
  144. package/build/modern/HydrationBoundary.cjs.map +1 -1
  145. package/build/modern/HydrationBoundary.d.cts +61 -0
  146. package/build/modern/HydrationBoundary.d.cts.map +1 -1
  147. package/build/modern/HydrationBoundary.d.ts +61 -0
  148. package/build/modern/HydrationBoundary.d.ts.map +1 -1
  149. package/build/modern/HydrationBoundary.js +43 -0
  150. package/build/modern/HydrationBoundary.js.map +1 -1
  151. package/build/modern/IsRestoringProvider.cjs +11 -0
  152. package/build/modern/IsRestoringProvider.cjs.map +1 -1
  153. package/build/modern/IsRestoringProvider.d.cts +11 -0
  154. package/build/modern/IsRestoringProvider.d.cts.map +1 -1
  155. package/build/modern/IsRestoringProvider.d.ts +11 -0
  156. package/build/modern/IsRestoringProvider.d.ts.map +1 -1
  157. package/build/modern/IsRestoringProvider.js +11 -0
  158. package/build/modern/IsRestoringProvider.js.map +1 -1
  159. package/build/modern/QueryClientProvider.cjs +30 -0
  160. package/build/modern/QueryClientProvider.cjs.map +1 -1
  161. package/build/modern/QueryClientProvider.d.cts +41 -0
  162. package/build/modern/QueryClientProvider.d.cts.map +1 -1
  163. package/build/modern/QueryClientProvider.d.ts +41 -0
  164. package/build/modern/QueryClientProvider.d.ts.map +1 -1
  165. package/build/modern/QueryClientProvider.js +30 -0
  166. package/build/modern/QueryClientProvider.js.map +1 -1
  167. package/build/modern/QueryErrorResetBoundary.cjs +75 -0
  168. package/build/modern/QueryErrorResetBoundary.cjs.map +1 -1
  169. package/build/modern/QueryErrorResetBoundary.d.cts +106 -0
  170. package/build/modern/QueryErrorResetBoundary.d.cts.map +1 -1
  171. package/build/modern/QueryErrorResetBoundary.d.ts +106 -0
  172. package/build/modern/QueryErrorResetBoundary.d.ts.map +1 -1
  173. package/build/modern/QueryErrorResetBoundary.js +75 -0
  174. package/build/modern/QueryErrorResetBoundary.js.map +1 -1
  175. package/build/modern/infiniteQueryOptions.cjs.map +1 -1
  176. package/build/modern/infiniteQueryOptions.d.cts +187 -0
  177. package/build/modern/infiniteQueryOptions.d.cts.map +1 -1
  178. package/build/modern/infiniteQueryOptions.d.ts +187 -0
  179. package/build/modern/infiniteQueryOptions.d.ts.map +1 -1
  180. package/build/modern/infiniteQueryOptions.js.map +1 -1
  181. package/build/modern/mutationOptions.cjs.map +1 -1
  182. package/build/modern/mutationOptions.d.cts +68 -0
  183. package/build/modern/mutationOptions.d.cts.map +1 -1
  184. package/build/modern/mutationOptions.d.ts +68 -0
  185. package/build/modern/mutationOptions.d.ts.map +1 -1
  186. package/build/modern/mutationOptions.js.map +1 -1
  187. package/build/modern/queryOptions.cjs.map +1 -1
  188. package/build/modern/queryOptions.d.cts +198 -0
  189. package/build/modern/queryOptions.d.cts.map +1 -1
  190. package/build/modern/queryOptions.d.ts +198 -0
  191. package/build/modern/queryOptions.d.ts.map +1 -1
  192. package/build/modern/queryOptions.js.map +1 -1
  193. package/build/modern/types.cjs.map +1 -1
  194. package/build/modern/types.d.cts +228 -2
  195. package/build/modern/types.d.cts.map +1 -1
  196. package/build/modern/types.d.ts +228 -2
  197. package/build/modern/types.d.ts.map +1 -1
  198. package/build/modern/types.js.map +1 -1
  199. package/build/modern/useInfiniteQuery.cjs.map +1 -1
  200. package/build/modern/useInfiniteQuery.d.cts +116 -0
  201. package/build/modern/useInfiniteQuery.d.cts.map +1 -1
  202. package/build/modern/useInfiniteQuery.d.ts +116 -0
  203. package/build/modern/useInfiniteQuery.d.ts.map +1 -1
  204. package/build/modern/useInfiniteQuery.js.map +1 -1
  205. package/build/modern/useIsFetching.cjs +20 -0
  206. package/build/modern/useIsFetching.cjs.map +1 -1
  207. package/build/modern/useIsFetching.d.cts +20 -0
  208. package/build/modern/useIsFetching.d.cts.map +1 -1
  209. package/build/modern/useIsFetching.d.ts +20 -0
  210. package/build/modern/useIsFetching.d.ts.map +1 -1
  211. package/build/modern/useIsFetching.js +20 -0
  212. package/build/modern/useIsFetching.js.map +1 -1
  213. package/build/modern/useMutation.cjs +67 -0
  214. package/build/modern/useMutation.cjs.map +1 -1
  215. package/build/modern/useMutation.d.cts +67 -0
  216. package/build/modern/useMutation.d.cts.map +1 -1
  217. package/build/modern/useMutation.d.ts +67 -0
  218. package/build/modern/useMutation.d.ts.map +1 -1
  219. package/build/modern/useMutation.js +67 -0
  220. package/build/modern/useMutation.js.map +1 -1
  221. package/build/modern/useMutationState.cjs +74 -0
  222. package/build/modern/useMutationState.cjs.map +1 -1
  223. package/build/modern/useMutationState.d.cts +74 -0
  224. package/build/modern/useMutationState.d.cts.map +1 -1
  225. package/build/modern/useMutationState.d.ts +74 -0
  226. package/build/modern/useMutationState.d.ts.map +1 -1
  227. package/build/modern/useMutationState.js +74 -0
  228. package/build/modern/useMutationState.js.map +1 -1
  229. package/build/modern/usePrefetchInfiniteQuery.cjs +44 -0
  230. package/build/modern/usePrefetchInfiniteQuery.cjs.map +1 -1
  231. package/build/modern/usePrefetchInfiniteQuery.d.cts +44 -0
  232. package/build/modern/usePrefetchInfiniteQuery.d.cts.map +1 -1
  233. package/build/modern/usePrefetchInfiniteQuery.d.ts +44 -0
  234. package/build/modern/usePrefetchInfiniteQuery.d.ts.map +1 -1
  235. package/build/modern/usePrefetchInfiniteQuery.js +44 -0
  236. package/build/modern/usePrefetchInfiniteQuery.js.map +1 -1
  237. package/build/modern/usePrefetchQuery.cjs +36 -1
  238. package/build/modern/usePrefetchQuery.cjs.map +1 -1
  239. package/build/modern/usePrefetchQuery.d.cts +35 -0
  240. package/build/modern/usePrefetchQuery.d.cts.map +1 -1
  241. package/build/modern/usePrefetchQuery.d.ts +35 -0
  242. package/build/modern/usePrefetchQuery.d.ts.map +1 -1
  243. package/build/modern/usePrefetchQuery.js +36 -1
  244. package/build/modern/usePrefetchQuery.js.map +1 -1
  245. package/build/modern/useQueries.cjs +50 -0
  246. package/build/modern/useQueries.cjs.map +1 -1
  247. package/build/modern/useQueries.d.cts +85 -2
  248. package/build/modern/useQueries.d.cts.map +1 -1
  249. package/build/modern/useQueries.d.ts +85 -2
  250. package/build/modern/useQueries.d.ts.map +1 -1
  251. package/build/modern/useQueries.js +50 -0
  252. package/build/modern/useQueries.js.map +1 -1
  253. package/build/modern/useQuery.cjs.map +1 -1
  254. package/build/modern/useQuery.d.cts +134 -0
  255. package/build/modern/useQuery.d.cts.map +1 -1
  256. package/build/modern/useQuery.d.ts +134 -0
  257. package/build/modern/useQuery.d.ts.map +1 -1
  258. package/build/modern/useQuery.js.map +1 -1
  259. package/build/modern/useSuspenseInfiniteQuery.cjs +48 -0
  260. package/build/modern/useSuspenseInfiniteQuery.cjs.map +1 -1
  261. package/build/modern/useSuspenseInfiniteQuery.d.cts +48 -0
  262. package/build/modern/useSuspenseInfiniteQuery.d.cts.map +1 -1
  263. package/build/modern/useSuspenseInfiniteQuery.d.ts +48 -0
  264. package/build/modern/useSuspenseInfiniteQuery.d.ts.map +1 -1
  265. package/build/modern/useSuspenseInfiniteQuery.js +48 -0
  266. package/build/modern/useSuspenseInfiniteQuery.js.map +1 -1
  267. package/build/modern/useSuspenseQueries.cjs.map +1 -1
  268. package/build/modern/useSuspenseQueries.d.cts +128 -2
  269. package/build/modern/useSuspenseQueries.d.cts.map +1 -1
  270. package/build/modern/useSuspenseQueries.d.ts +128 -2
  271. package/build/modern/useSuspenseQueries.d.ts.map +1 -1
  272. package/build/modern/useSuspenseQueries.js.map +1 -1
  273. package/build/modern/useSuspenseQuery.cjs +43 -0
  274. package/build/modern/useSuspenseQuery.cjs.map +1 -1
  275. package/build/modern/useSuspenseQuery.d.cts +43 -0
  276. package/build/modern/useSuspenseQuery.d.cts.map +1 -1
  277. package/build/modern/useSuspenseQuery.d.ts +43 -0
  278. package/build/modern/useSuspenseQuery.d.ts.map +1 -1
  279. package/build/modern/useSuspenseQuery.js +43 -0
  280. package/build/modern/useSuspenseQuery.js.map +1 -1
  281. package/build/modern/utils.cjs.map +1 -1
  282. package/build/modern/utils.d.cts.map +1 -1
  283. package/build/modern/utils.d.ts.map +1 -1
  284. package/build/modern/utils.js.map +1 -1
  285. package/package.json +3 -3
  286. package/src/HydrationBoundary.tsx +61 -1
  287. package/src/IsRestoringProvider.ts +12 -0
  288. package/src/QueryClientProvider.tsx +41 -0
  289. package/src/QueryErrorResetBoundary.tsx +109 -0
  290. package/src/infiniteQueryOptions.ts +187 -0
  291. package/src/mutationOptions.ts +68 -0
  292. package/src/queryOptions.ts +198 -0
  293. package/src/types.ts +228 -2
  294. package/src/useInfiniteQuery.ts +116 -0
  295. package/src/useIsFetching.ts +20 -0
  296. package/src/useMutation.ts +67 -0
  297. package/src/useMutationState.ts +74 -0
  298. package/src/usePrefetchInfiniteQuery.tsx +44 -0
  299. package/src/usePrefetchQuery.tsx +36 -1
  300. package/src/useQueries.ts +85 -2
  301. package/src/useQuery.ts +134 -0
  302. package/src/useSuspenseInfiniteQuery.ts +48 -0
  303. package/src/useSuspenseQueries.ts +128 -2
  304. package/src/useSuspenseQuery.ts +43 -0
  305. package/src/utils.ts +0 -1
@@ -3,5 +3,17 @@ import { useContext } from 'preact/hooks'
3
3
 
4
4
  const IsRestoringContext = createContext(false)
5
5
 
6
+ /**
7
+ * If you are using `PersistQueryClientProvider`, you can also use the `useIsRestoring` hook alongside it to
8
+ * check if a restore is currently in progress. `useQuery` and friends also check this internally to avoid
9
+ * race conditions between the restore and mounting queries.
10
+ *
11
+ * @returns `true` while a persisted client is being restored, `false` otherwise.
12
+ */
6
13
  export const useIsRestoring = () => useContext(IsRestoringContext)
14
+
15
+ /**
16
+ * The Provider that `PersistQueryClientProvider` uses to signal whether a persisted client is currently
17
+ * being restored, read by `useIsRestoring`.
18
+ */
7
19
  export const IsRestoringProvider = IsRestoringContext.Provider
@@ -3,10 +3,21 @@ import { createContext } from 'preact'
3
3
  import type { ComponentChildren, VNode } from 'preact'
4
4
  import { useContext, useEffect } from 'preact/hooks'
5
5
 
6
+ /**
7
+ * The context that `useQueryClient` reads from. `QueryClientProvider` is the normal way to set it.
8
+ */
6
9
  export const QueryClientContext = createContext<QueryClient | undefined>(
7
10
  undefined,
8
11
  )
9
12
 
13
+ /**
14
+ * The `useQueryClient` hook returns the current `QueryClient` instance.
15
+ *
16
+ * @param queryClient - Use this to use a custom `QueryClient`. Otherwise, the one from the nearest context will
17
+ * be used.
18
+ * @returns The current `QueryClient` instance.
19
+ * @throws If no `queryClient` argument is passed and no `QueryClientProvider` is found in the component tree.
20
+ */
10
21
  export const useQueryClient = (queryClient?: QueryClient) => {
11
22
  const client = useContext(QueryClientContext)
12
23
 
@@ -21,11 +32,41 @@ export const useQueryClient = (queryClient?: QueryClient) => {
21
32
  return client
22
33
  }
23
34
 
35
+ /**
36
+ * The props accepted by `QueryClientProvider`.
37
+ */
24
38
  export type QueryClientProviderProps = {
39
+ /**
40
+ * **Required**
41
+ *
42
+ * The `QueryClient` instance to provide.
43
+ */
25
44
  client: QueryClient
45
+ /**
46
+ * The components that get access to the provided `QueryClient`.
47
+ */
26
48
  children?: ComponentChildren
27
49
  }
28
50
 
51
+ /**
52
+ * Use the `QueryClientProvider` component to connect and provide a `QueryClient` to your application. Also
53
+ * calls `client.mount()`/`client.unmount()` as this component mounts/unmounts, which subscribes the client to
54
+ * focus/online events (resuming any paused mutations and refetching as needed when the app regains focus or
55
+ * comes back online).
56
+ *
57
+ * @returns The provided `children`, wrapped so they can read the `QueryClient` via `useQueryClient`.
58
+ *
59
+ * @example
60
+ * ```tsx
61
+ * import { QueryClient, QueryClientProvider } from '@tanstack/preact-query'
62
+ *
63
+ * const queryClient = new QueryClient()
64
+ *
65
+ * function App() {
66
+ * return <QueryClientProvider client={queryClient}>...</QueryClientProvider>
67
+ * }
68
+ * ```
69
+ */
29
70
  export const QueryClientProvider = ({
30
71
  client,
31
72
  children,
@@ -3,13 +3,34 @@ import type { ComponentChildren } from 'preact'
3
3
  import { useContext, useState } from 'preact/hooks'
4
4
 
5
5
  // CONTEXT
6
+
7
+ /**
8
+ * Resets any query errors within the boundary, so queries know they can try again.
9
+ */
6
10
  export type QueryErrorResetFunction = () => void
11
+
12
+ /**
13
+ * Returns whether the boundary has been reset and not yet cleared.
14
+ */
7
15
  export type QueryErrorIsResetFunction = () => boolean
16
+
17
+ /**
18
+ * Clears the reset state, so queries know not to try again until the boundary is reset again.
19
+ */
8
20
  export type QueryErrorClearResetFunction = () => void
9
21
 
10
22
  export interface QueryErrorResetBoundaryValue {
23
+ /**
24
+ * Clears the reset state, so queries know not to try again until the boundary is reset again.
25
+ */
11
26
  clearReset: QueryErrorClearResetFunction
27
+ /**
28
+ * Returns whether the boundary has been reset and not yet cleared.
29
+ */
12
30
  isReset: QueryErrorIsResetFunction
31
+ /**
32
+ * Resets any query errors within the boundary, so queries know they can try again.
33
+ */
13
34
  reset: QueryErrorResetFunction
14
35
  }
15
36
 
@@ -32,19 +53,107 @@ const QueryErrorResetBoundaryContext = createContext(createValue())
32
53
 
33
54
  // HOOK
34
55
 
56
+ /**
57
+ * This hook will reset any query errors within the closest `QueryErrorResetBoundary`. If there is no boundary
58
+ * defined it will reset them globally.
59
+ *
60
+ * @returns The boundary's {@link QueryErrorResetBoundaryValue}.
61
+ *
62
+ * @example
63
+ * ```tsx
64
+ * import { useErrorBoundary } from 'preact/hooks'
65
+ * import type { ComponentChildren } from 'preact'
66
+ * import { useQueryErrorResetBoundary } from '@tanstack/preact-query'
67
+ *
68
+ * function App({ children }: { children: ComponentChildren }) {
69
+ * const { reset } = useQueryErrorResetBoundary()
70
+ * const [error, resetError] = useErrorBoundary(() => reset())
71
+ *
72
+ * if (error) {
73
+ * return (
74
+ * <div>
75
+ * There was an error!
76
+ * <button onClick={() => resetError()}>Try again</button>
77
+ * </div>
78
+ * )
79
+ * }
80
+ *
81
+ * return children
82
+ * }
83
+ * ```
84
+ */
35
85
  export const useQueryErrorResetBoundary = () =>
36
86
  useContext(QueryErrorResetBoundaryContext)
37
87
 
38
88
  // COMPONENT
39
89
 
90
+ /**
91
+ * A render-prop function usable as `children` on `QueryErrorResetBoundary`.
92
+ *
93
+ * @param value - The boundary's {@link QueryErrorResetBoundaryValue}.
94
+ * @returns The children to render.
95
+ */
40
96
  export type QueryErrorResetBoundaryFunction = (
41
97
  value: QueryErrorResetBoundaryValue,
42
98
  ) => ComponentChildren
43
99
 
100
+ /**
101
+ * The props accepted by `QueryErrorResetBoundary`.
102
+ */
44
103
  export interface QueryErrorResetBoundaryProps {
104
+ /**
105
+ * Either a plain node, or a function that receives the boundary's {@link QueryErrorResetBoundaryValue} and
106
+ * returns a node.
107
+ */
45
108
  children: QueryErrorResetBoundaryFunction | ComponentChildren
46
109
  }
47
110
 
111
+ /**
112
+ * When using `suspense` or `throwOnError` in your queries, you need a way to let queries know that you want to
113
+ * try again when re-rendering after some error occurred. With the `QueryErrorResetBoundary` component you can
114
+ * reset any query errors within the boundaries of the component.
115
+ *
116
+ * @returns The `children`, rendered as-is, or called with the boundary's {@link QueryErrorResetBoundaryValue}
117
+ * if `children` is a function.
118
+ *
119
+ * @example
120
+ * ```tsx
121
+ * import { useErrorBoundary } from 'preact/hooks'
122
+ * import type { ComponentChildren } from 'preact'
123
+ * import { QueryErrorResetBoundary } from '@tanstack/preact-query'
124
+ *
125
+ * function ErrorBoundary({
126
+ * children,
127
+ * reset,
128
+ * }: {
129
+ * children: ComponentChildren
130
+ * reset: () => void
131
+ * }) {
132
+ * const [error, resetError] = useErrorBoundary(() => reset())
133
+ *
134
+ * if (error) {
135
+ * return (
136
+ * <div>
137
+ * There was an error!
138
+ * <button onClick={() => resetError()}>Try again</button>
139
+ * </div>
140
+ * )
141
+ * }
142
+ *
143
+ * return children
144
+ * }
145
+ *
146
+ * const App = () => (
147
+ * <QueryErrorResetBoundary>
148
+ * {({ reset }) => (
149
+ * <ErrorBoundary reset={reset}>
150
+ * <Page />
151
+ * </ErrorBoundary>
152
+ * )}
153
+ * </QueryErrorResetBoundary>
154
+ * )
155
+ * ```
156
+ */
48
157
  export const QueryErrorResetBoundary = ({
49
158
  children,
50
159
  }: QueryErrorResetBoundaryProps) => {
@@ -11,6 +11,17 @@ import type {
11
11
 
12
12
  import type { UseInfiniteQueryOptions } from './types'
13
13
 
14
+ /**
15
+ * The options accepted by the `infiniteQueryOptions` overload selected when no `initialData` is set — `data`
16
+ * may be `undefined` while the query is `pending`.
17
+ *
18
+ * @template TQueryFnData - The type of a single page, as your `queryFn` resolves it.
19
+ * @template TError - The type of errors your `queryFn` may throw.
20
+ * @template TData - The type `data` ends up as after `select` runs — defaults to `InfiniteData<TQueryFnData>`,
21
+ * the shape of all fetched pages plus their page params.
22
+ * @template TQueryKey - The type of your `queryKey`.
23
+ * @template TPageParam - The type of the parameter passed to `queryFn` to fetch a given page.
24
+ */
14
25
  export type UndefinedInitialDataInfiniteOptions<
15
26
  TQueryFnData,
16
27
  TError = DefaultError,
@@ -24,6 +35,13 @@ export type UndefinedInitialDataInfiniteOptions<
24
35
  TQueryKey,
25
36
  TPageParam
26
37
  > & {
38
+ /**
39
+ * If set, this value will be used as the initial data for the query cache (as long as the query hasn't been
40
+ * created or cached yet). If set to a function, the function will be called **once** during the shared/root
41
+ * query initialization, and be expected to synchronously return the initial data. Initial data is
42
+ * considered stale by default unless a `staleTime` has been set. `initialData` **is persisted** to the
43
+ * cache.
44
+ */
27
45
  initialData?:
28
46
  | undefined
29
47
  | NonUndefinedGuard<InfiniteData<TQueryFnData, TPageParam>>
@@ -32,6 +50,18 @@ export type UndefinedInitialDataInfiniteOptions<
32
50
  >
33
51
  }
34
52
 
53
+ /**
54
+ * The options accepted by the `infiniteQueryOptions` overload selected when no `initialData` is set and
55
+ * `queryFn` is not `skipToken` — same as {@link UndefinedInitialDataInfiniteOptions}, but `queryFn` may not be
56
+ * `skipToken`.
57
+ *
58
+ * @template TQueryFnData - The type of a single page, as your `queryFn` resolves it.
59
+ * @template TError - The type of errors your `queryFn` may throw.
60
+ * @template TData - The type `data` ends up as after `select` runs — defaults to `InfiniteData<TQueryFnData>`,
61
+ * the shape of all fetched pages plus their page params.
62
+ * @template TQueryKey - The type of your `queryKey`.
63
+ * @template TPageParam - The type of the parameter passed to `queryFn` to fetch a given page.
64
+ */
35
65
  export type UnusedSkipTokenInfiniteOptions<
36
66
  TQueryFnData,
37
67
  TError = DefaultError,
@@ -42,6 +72,10 @@ export type UnusedSkipTokenInfiniteOptions<
42
72
  UseInfiniteQueryOptions<TQueryFnData, TError, TData, TQueryKey, TPageParam>,
43
73
  'queryFn'
44
74
  > & {
75
+ /**
76
+ * `skipToken` is not allowed as a value here — this overload is selected when no `initialData` is set. If
77
+ * you don't intend to run the query yet, omit `queryFn` or use a default query function instead.
78
+ */
45
79
  queryFn?: Exclude<
46
80
  UseInfiniteQueryOptions<
47
81
  TQueryFnData,
@@ -54,6 +88,17 @@ export type UnusedSkipTokenInfiniteOptions<
54
88
  >
55
89
  }
56
90
 
91
+ /**
92
+ * The options accepted by the `infiniteQueryOptions` overload selected when `initialData` is set — `data` is
93
+ * never `undefined`.
94
+ *
95
+ * @template TQueryFnData - The type of a single page, as your `queryFn` resolves it.
96
+ * @template TError - The type of errors your `queryFn` may throw.
97
+ * @template TData - The type `data` ends up as after `select` runs — defaults to `InfiniteData<TQueryFnData>`,
98
+ * the shape of all fetched pages plus their page params.
99
+ * @template TQueryKey - The type of your `queryKey`.
100
+ * @template TPageParam - The type of the parameter passed to `queryFn` to fetch a given page.
101
+ */
57
102
  export type DefinedInitialDataInfiniteOptions<
58
103
  TQueryFnData,
59
104
  TError = DefaultError,
@@ -67,12 +112,48 @@ export type DefinedInitialDataInfiniteOptions<
67
112
  TQueryKey,
68
113
  TPageParam
69
114
  > & {
115
+ /**
116
+ * If set, this value will be used as the initial data for the query cache (as long as the query hasn't been
117
+ * created or cached yet). If set to a function, the function will be called **once** during the shared/root
118
+ * query initialization, and be expected to synchronously return the initial data. Initial data is
119
+ * considered stale by default unless a `staleTime` has been set. `initialData` **is persisted** to the
120
+ * cache.
121
+ */
70
122
  initialData:
71
123
  | NonUndefinedGuard<InfiniteData<TQueryFnData, TPageParam>>
72
124
  | (() => NonUndefinedGuard<InfiniteData<TQueryFnData, TPageParam>>)
73
125
  | undefined
74
126
  }
75
127
 
128
+ /**
129
+ * You can generally pass everything to `infiniteQueryOptions` that you can also pass to `useInfiniteQuery`.
130
+ * These options can be shared across hooks and imperative APIs such as `queryClient.infiniteQuery`.
131
+ * `options.queryKey` is required and is the query key to generate options for.
132
+ *
133
+ * This overload is selected when `initialData` is set.
134
+ *
135
+ * @see {@link useInfiniteQuery} to run an infinite query with these options.
136
+ * @param options - The {@link DefinedInitialDataInfiniteOptions} to use — everything you can pass to `useInfiniteQuery`, with `initialData` set.
137
+ * @returns The same options object, typed so that `queryKey` carries the inferred data type.
138
+ *
139
+ * @example
140
+ * ```tsx
141
+ * import { infiniteQueryOptions, useInfiniteQuery } from '@tanstack/preact-query'
142
+ *
143
+ * export const projectsOptions = infiniteQueryOptions({
144
+ * queryKey: ['projects'],
145
+ * queryFn: ({ pageParam }) => fetchProjects(pageParam),
146
+ * initialPageParam: 0,
147
+ * getNextPageParam: (lastPage) => lastPage.nextId,
148
+ * initialData: { pages: [], pageParams: [] },
149
+ * })
150
+ *
151
+ * function Projects() {
152
+ * const { data } = useInfiniteQuery(projectsOptions)
153
+ * return <>{data.pages.map((page) => page.projects.map((p) => <p key={p.id}>{p.name}</p>))}</>
154
+ * }
155
+ * ```
156
+ */
76
157
  export function infiniteQueryOptions<
77
158
  TQueryFnData,
78
159
  TError = DefaultError,
@@ -96,6 +177,59 @@ export function infiniteQueryOptions<
96
177
  > &
97
178
  QueryKeyWithDataTag<TQueryKey, InfiniteData<TQueryFnData>, TError>
98
179
 
180
+ /**
181
+ * You can generally pass everything to `infiniteQueryOptions` that you can also pass to `useInfiniteQuery`.
182
+ * These options can be shared across hooks and imperative APIs such as `queryClient.infiniteQuery`.
183
+ * `options.queryKey` is required and is the query key to generate options for.
184
+ *
185
+ * @returns The same options object, typed so that `queryKey` carries the inferred data type.
186
+ *
187
+ * @example
188
+ * ```tsx
189
+ * import { infiniteQueryOptions } from '@tanstack/preact-query'
190
+ *
191
+ * export const projectsOptions = infiniteQueryOptions({
192
+ * queryKey: ['projects'],
193
+ * queryFn: ({ pageParam }) => fetchProjects(pageParam),
194
+ * initialPageParam: 0,
195
+ * getNextPageParam: (lastPage) => lastPage.nextId,
196
+ * })
197
+ * ```
198
+ *
199
+ * @example
200
+ * A parameterized factory, reused across a hook and an imperative call with the same cache entry:
201
+ * ```tsx
202
+ * import {
203
+ * infiniteQueryOptions,
204
+ * noop,
205
+ * useInfiniteQuery,
206
+ * } from '@tanstack/preact-query'
207
+ *
208
+ * export const commentsOptions = (postId: string) =>
209
+ * infiniteQueryOptions({
210
+ * queryKey: ['post', postId, 'comments'],
211
+ * queryFn: ({ pageParam }) => fetchComments(postId, pageParam),
212
+ * initialPageParam: 0,
213
+ * getNextPageParam: (lastPage) => lastPage.nextId,
214
+ * })
215
+ *
216
+ * function Comments({ postId }: { postId: string }) {
217
+ * const result = useInfiniteQuery(commentsOptions(postId))
218
+ * if (!result.isSuccess) return 'Loading...'
219
+ * return (
220
+ * <>
221
+ * {result.data.pages.map((page) => page.comments.map((c) => <p key={c.id}>{c.text}</p>))}
222
+ * </>
223
+ * )
224
+ * }
225
+ *
226
+ * // Elsewhere, e.g. to warm the cache before rendering `<Comments>`:
227
+ * queryClient.infiniteQuery(commentsOptions(postId)).catch(noop)
228
+ * ```
229
+ *
230
+ * @see {@link useInfiniteQuery} to run an infinite query with these options.
231
+ * @param options - The {@link UnusedSkipTokenInfiniteOptions} to use — everything you can pass to `useInfiniteQuery`.
232
+ */
99
233
  export function infiniteQueryOptions<
100
234
  TQueryFnData,
101
235
  TError = DefaultError,
@@ -119,6 +253,59 @@ export function infiniteQueryOptions<
119
253
  > &
120
254
  QueryKeyWithDataTag<TQueryKey, InfiniteData<TQueryFnData>, TError>
121
255
 
256
+ /**
257
+ * You can generally pass everything to `infiniteQueryOptions` that you can also pass to `useInfiniteQuery`.
258
+ * These options can be shared across hooks and imperative APIs such as `queryClient.infiniteQuery`.
259
+ * `options.queryKey` is required and is the query key to generate options for.
260
+ *
261
+ * @returns The same options object, typed so that `queryKey` carries the inferred data type.
262
+ *
263
+ * @example
264
+ * ```tsx
265
+ * import { infiniteQueryOptions } from '@tanstack/preact-query'
266
+ *
267
+ * export const projectsOptions = infiniteQueryOptions({
268
+ * queryKey: ['projects'],
269
+ * queryFn: ({ pageParam }) => fetchProjects(pageParam),
270
+ * initialPageParam: 0,
271
+ * getNextPageParam: (lastPage) => lastPage.nextId,
272
+ * })
273
+ * ```
274
+ *
275
+ * @example
276
+ * A parameterized factory, reused across a hook and an imperative call with the same cache entry:
277
+ * ```tsx
278
+ * import {
279
+ * infiniteQueryOptions,
280
+ * noop,
281
+ * useInfiniteQuery,
282
+ * } from '@tanstack/preact-query'
283
+ *
284
+ * export const commentsOptions = (postId: string) =>
285
+ * infiniteQueryOptions({
286
+ * queryKey: ['post', postId, 'comments'],
287
+ * queryFn: ({ pageParam }) => fetchComments(postId, pageParam),
288
+ * initialPageParam: 0,
289
+ * getNextPageParam: (lastPage) => lastPage.nextId,
290
+ * })
291
+ *
292
+ * function Comments({ postId }: { postId: string }) {
293
+ * const result = useInfiniteQuery(commentsOptions(postId))
294
+ * if (!result.isSuccess) return 'Loading...'
295
+ * return (
296
+ * <>
297
+ * {result.data.pages.map((page) => page.comments.map((c) => <p key={c.id}>{c.text}</p>))}
298
+ * </>
299
+ * )
300
+ * }
301
+ *
302
+ * // Elsewhere, e.g. to warm the cache before rendering `<Comments>`:
303
+ * queryClient.infiniteQuery(commentsOptions(postId)).catch(noop)
304
+ * ```
305
+ *
306
+ * @see {@link useInfiniteQuery} to run an infinite query with these options.
307
+ * @param options - The {@link UndefinedInitialDataInfiniteOptions} to use — everything you can pass to `useInfiniteQuery`.
308
+ */
122
309
  export function infiniteQueryOptions<
123
310
  TQueryFnData,
124
311
  TError = DefaultError,
@@ -2,6 +2,50 @@ import type { DefaultError, WithRequired } from '@tanstack/query-core'
2
2
 
3
3
  import type { UseMutationOptions } from './types'
4
4
 
5
+ /**
6
+ * You can generally pass everything to `mutationOptions` that you can also pass to `useMutation`. A
7
+ * `mutationKey` is required on this overload so the mutation can be looked up later, e.g. with
8
+ * `useMutationState`.
9
+ *
10
+ * @see {@link useMutation} to run the mutation these options describe.
11
+ * @param options - The mutation options to use, identical to what you'd pass to `useMutation`, with a
12
+ * required `mutationKey`.
13
+ * @returns The same options object, unchanged.
14
+ *
15
+ * @example
16
+ * ```tsx
17
+ * import { mutationOptions, useMutation } from '@tanstack/preact-query'
18
+ *
19
+ * export const createPostOptions = mutationOptions({
20
+ * mutationKey: ['posts', 'create'],
21
+ * mutationFn: createPost,
22
+ * })
23
+ *
24
+ * function CreatePost() {
25
+ * const mutation = useMutation(createPostOptions)
26
+ * return <button onClick={() => mutation.mutate({ title: 'Hello' })}>Create</button>
27
+ * }
28
+ * ```
29
+ *
30
+ * @example
31
+ * Looking the mutation up elsewhere via its `mutationKey`, e.g. for a global "saving…" indicator:
32
+ * ```tsx
33
+ * import { mutationOptions, useMutationState } from '@tanstack/preact-query'
34
+ *
35
+ * const createPostOptions = mutationOptions({
36
+ * mutationKey: ['posts', 'create'],
37
+ * mutationFn: createPost,
38
+ * })
39
+ *
40
+ * function SavingIndicator() {
41
+ * const isCreatingPost = useMutationState({
42
+ * filters: { mutationKey: createPostOptions.mutationKey, status: 'pending' },
43
+ * }).length > 0
44
+ *
45
+ * return isCreatingPost ? <span>Saving…</span> : null
46
+ * }
47
+ * ```
48
+ */
5
49
  export function mutationOptions<
6
50
  TData = unknown,
7
51
  TError = DefaultError,
@@ -16,6 +60,30 @@ export function mutationOptions<
16
60
  UseMutationOptions<TData, TError, TVariables, TOnMutateResult>,
17
61
  'mutationKey'
18
62
  >
63
+ /**
64
+ * You can generally pass everything to `mutationOptions` that you can also pass to `useMutation`. No
65
+ * `mutationKey` is required on this overload — use this when you don't need to look the mutation up later
66
+ * (e.g. with `useMutationState`).
67
+ *
68
+ * @see {@link useMutation} to run the mutation these options describe.
69
+ * @param options - The mutation options to use, identical to what you'd pass to `useMutation`, without a
70
+ * `mutationKey`.
71
+ * @returns The same options object, unchanged.
72
+ *
73
+ * @example
74
+ * ```tsx
75
+ * import { mutationOptions, useMutation } from '@tanstack/preact-query'
76
+ *
77
+ * export const createPostOptions = mutationOptions({
78
+ * mutationFn: createPost,
79
+ * })
80
+ *
81
+ * function CreatePost() {
82
+ * const mutation = useMutation(createPostOptions)
83
+ * return <button onClick={() => mutation.mutate({ title: 'Hello' })}>Create</button>
84
+ * }
85
+ * ```
86
+ */
19
87
  export function mutationOptions<
20
88
  TData = unknown,
21
89
  TError = DefaultError,