@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.
- package/build/legacy/HydrationBoundary.cjs +43 -0
- package/build/legacy/HydrationBoundary.cjs.map +1 -1
- package/build/legacy/HydrationBoundary.d.cts +61 -0
- package/build/legacy/HydrationBoundary.d.cts.map +1 -1
- package/build/legacy/HydrationBoundary.d.ts +61 -0
- package/build/legacy/HydrationBoundary.d.ts.map +1 -1
- package/build/legacy/HydrationBoundary.js +43 -0
- package/build/legacy/HydrationBoundary.js.map +1 -1
- package/build/legacy/IsRestoringProvider.cjs +11 -0
- package/build/legacy/IsRestoringProvider.cjs.map +1 -1
- package/build/legacy/IsRestoringProvider.d.cts +11 -0
- package/build/legacy/IsRestoringProvider.d.cts.map +1 -1
- package/build/legacy/IsRestoringProvider.d.ts +11 -0
- package/build/legacy/IsRestoringProvider.d.ts.map +1 -1
- package/build/legacy/IsRestoringProvider.js +11 -0
- package/build/legacy/IsRestoringProvider.js.map +1 -1
- package/build/legacy/QueryClientProvider.cjs +30 -0
- package/build/legacy/QueryClientProvider.cjs.map +1 -1
- package/build/legacy/QueryClientProvider.d.cts +41 -0
- package/build/legacy/QueryClientProvider.d.cts.map +1 -1
- package/build/legacy/QueryClientProvider.d.ts +41 -0
- package/build/legacy/QueryClientProvider.d.ts.map +1 -1
- package/build/legacy/QueryClientProvider.js +30 -0
- package/build/legacy/QueryClientProvider.js.map +1 -1
- package/build/legacy/QueryErrorResetBoundary.cjs +75 -0
- package/build/legacy/QueryErrorResetBoundary.cjs.map +1 -1
- package/build/legacy/QueryErrorResetBoundary.d.cts +106 -0
- package/build/legacy/QueryErrorResetBoundary.d.cts.map +1 -1
- package/build/legacy/QueryErrorResetBoundary.d.ts +106 -0
- package/build/legacy/QueryErrorResetBoundary.d.ts.map +1 -1
- package/build/legacy/QueryErrorResetBoundary.js +75 -0
- package/build/legacy/QueryErrorResetBoundary.js.map +1 -1
- package/build/legacy/infiniteQueryOptions.cjs.map +1 -1
- package/build/legacy/infiniteQueryOptions.d.cts +187 -0
- package/build/legacy/infiniteQueryOptions.d.cts.map +1 -1
- package/build/legacy/infiniteQueryOptions.d.ts +187 -0
- package/build/legacy/infiniteQueryOptions.d.ts.map +1 -1
- package/build/legacy/infiniteQueryOptions.js.map +1 -1
- package/build/legacy/mutationOptions.cjs.map +1 -1
- package/build/legacy/mutationOptions.d.cts +68 -0
- package/build/legacy/mutationOptions.d.cts.map +1 -1
- package/build/legacy/mutationOptions.d.ts +68 -0
- package/build/legacy/mutationOptions.d.ts.map +1 -1
- package/build/legacy/mutationOptions.js.map +1 -1
- package/build/legacy/queryOptions.cjs.map +1 -1
- package/build/legacy/queryOptions.d.cts +198 -0
- package/build/legacy/queryOptions.d.cts.map +1 -1
- package/build/legacy/queryOptions.d.ts +198 -0
- package/build/legacy/queryOptions.d.ts.map +1 -1
- package/build/legacy/queryOptions.js.map +1 -1
- package/build/legacy/types.cjs.map +1 -1
- package/build/legacy/types.d.cts +228 -2
- package/build/legacy/types.d.cts.map +1 -1
- package/build/legacy/types.d.ts +228 -2
- package/build/legacy/types.d.ts.map +1 -1
- package/build/legacy/types.js.map +1 -1
- package/build/legacy/useInfiniteQuery.cjs.map +1 -1
- package/build/legacy/useInfiniteQuery.d.cts +116 -0
- package/build/legacy/useInfiniteQuery.d.cts.map +1 -1
- package/build/legacy/useInfiniteQuery.d.ts +116 -0
- package/build/legacy/useInfiniteQuery.d.ts.map +1 -1
- package/build/legacy/useInfiniteQuery.js.map +1 -1
- package/build/legacy/useIsFetching.cjs +20 -0
- package/build/legacy/useIsFetching.cjs.map +1 -1
- package/build/legacy/useIsFetching.d.cts +20 -0
- package/build/legacy/useIsFetching.d.cts.map +1 -1
- package/build/legacy/useIsFetching.d.ts +20 -0
- package/build/legacy/useIsFetching.d.ts.map +1 -1
- package/build/legacy/useIsFetching.js +20 -0
- package/build/legacy/useIsFetching.js.map +1 -1
- package/build/legacy/useMutation.cjs +67 -0
- package/build/legacy/useMutation.cjs.map +1 -1
- package/build/legacy/useMutation.d.cts +67 -0
- package/build/legacy/useMutation.d.cts.map +1 -1
- package/build/legacy/useMutation.d.ts +67 -0
- package/build/legacy/useMutation.d.ts.map +1 -1
- package/build/legacy/useMutation.js +67 -0
- package/build/legacy/useMutation.js.map +1 -1
- package/build/legacy/useMutationState.cjs +74 -0
- package/build/legacy/useMutationState.cjs.map +1 -1
- package/build/legacy/useMutationState.d.cts +74 -0
- package/build/legacy/useMutationState.d.cts.map +1 -1
- package/build/legacy/useMutationState.d.ts +74 -0
- package/build/legacy/useMutationState.d.ts.map +1 -1
- package/build/legacy/useMutationState.js +74 -0
- package/build/legacy/useMutationState.js.map +1 -1
- package/build/legacy/usePrefetchInfiniteQuery.cjs +44 -0
- package/build/legacy/usePrefetchInfiniteQuery.cjs.map +1 -1
- package/build/legacy/usePrefetchInfiniteQuery.d.cts +44 -0
- package/build/legacy/usePrefetchInfiniteQuery.d.cts.map +1 -1
- package/build/legacy/usePrefetchInfiniteQuery.d.ts +44 -0
- package/build/legacy/usePrefetchInfiniteQuery.d.ts.map +1 -1
- package/build/legacy/usePrefetchInfiniteQuery.js +44 -0
- package/build/legacy/usePrefetchInfiniteQuery.js.map +1 -1
- package/build/legacy/usePrefetchQuery.cjs +36 -1
- package/build/legacy/usePrefetchQuery.cjs.map +1 -1
- package/build/legacy/usePrefetchQuery.d.cts +35 -0
- package/build/legacy/usePrefetchQuery.d.cts.map +1 -1
- package/build/legacy/usePrefetchQuery.d.ts +35 -0
- package/build/legacy/usePrefetchQuery.d.ts.map +1 -1
- package/build/legacy/usePrefetchQuery.js +36 -1
- package/build/legacy/usePrefetchQuery.js.map +1 -1
- package/build/legacy/useQueries.cjs +50 -0
- package/build/legacy/useQueries.cjs.map +1 -1
- package/build/legacy/useQueries.d.cts +85 -2
- package/build/legacy/useQueries.d.cts.map +1 -1
- package/build/legacy/useQueries.d.ts +85 -2
- package/build/legacy/useQueries.d.ts.map +1 -1
- package/build/legacy/useQueries.js +50 -0
- package/build/legacy/useQueries.js.map +1 -1
- package/build/legacy/useQuery.cjs.map +1 -1
- package/build/legacy/useQuery.d.cts +134 -0
- package/build/legacy/useQuery.d.cts.map +1 -1
- package/build/legacy/useQuery.d.ts +134 -0
- package/build/legacy/useQuery.d.ts.map +1 -1
- package/build/legacy/useQuery.js.map +1 -1
- package/build/legacy/useSuspenseInfiniteQuery.cjs +48 -0
- package/build/legacy/useSuspenseInfiniteQuery.cjs.map +1 -1
- package/build/legacy/useSuspenseInfiniteQuery.d.cts +48 -0
- package/build/legacy/useSuspenseInfiniteQuery.d.cts.map +1 -1
- package/build/legacy/useSuspenseInfiniteQuery.d.ts +48 -0
- package/build/legacy/useSuspenseInfiniteQuery.d.ts.map +1 -1
- package/build/legacy/useSuspenseInfiniteQuery.js +48 -0
- package/build/legacy/useSuspenseInfiniteQuery.js.map +1 -1
- package/build/legacy/useSuspenseQueries.cjs.map +1 -1
- package/build/legacy/useSuspenseQueries.d.cts +128 -2
- package/build/legacy/useSuspenseQueries.d.cts.map +1 -1
- package/build/legacy/useSuspenseQueries.d.ts +128 -2
- package/build/legacy/useSuspenseQueries.d.ts.map +1 -1
- package/build/legacy/useSuspenseQueries.js.map +1 -1
- package/build/legacy/useSuspenseQuery.cjs +43 -0
- package/build/legacy/useSuspenseQuery.cjs.map +1 -1
- package/build/legacy/useSuspenseQuery.d.cts +43 -0
- package/build/legacy/useSuspenseQuery.d.cts.map +1 -1
- package/build/legacy/useSuspenseQuery.d.ts +43 -0
- package/build/legacy/useSuspenseQuery.d.ts.map +1 -1
- package/build/legacy/useSuspenseQuery.js +43 -0
- package/build/legacy/useSuspenseQuery.js.map +1 -1
- package/build/legacy/utils.cjs.map +1 -1
- package/build/legacy/utils.d.cts.map +1 -1
- package/build/legacy/utils.d.ts.map +1 -1
- package/build/legacy/utils.js.map +1 -1
- package/build/modern/HydrationBoundary.cjs +43 -0
- package/build/modern/HydrationBoundary.cjs.map +1 -1
- package/build/modern/HydrationBoundary.d.cts +61 -0
- package/build/modern/HydrationBoundary.d.cts.map +1 -1
- package/build/modern/HydrationBoundary.d.ts +61 -0
- package/build/modern/HydrationBoundary.d.ts.map +1 -1
- package/build/modern/HydrationBoundary.js +43 -0
- package/build/modern/HydrationBoundary.js.map +1 -1
- package/build/modern/IsRestoringProvider.cjs +11 -0
- package/build/modern/IsRestoringProvider.cjs.map +1 -1
- package/build/modern/IsRestoringProvider.d.cts +11 -0
- package/build/modern/IsRestoringProvider.d.cts.map +1 -1
- package/build/modern/IsRestoringProvider.d.ts +11 -0
- package/build/modern/IsRestoringProvider.d.ts.map +1 -1
- package/build/modern/IsRestoringProvider.js +11 -0
- package/build/modern/IsRestoringProvider.js.map +1 -1
- package/build/modern/QueryClientProvider.cjs +30 -0
- package/build/modern/QueryClientProvider.cjs.map +1 -1
- package/build/modern/QueryClientProvider.d.cts +41 -0
- package/build/modern/QueryClientProvider.d.cts.map +1 -1
- package/build/modern/QueryClientProvider.d.ts +41 -0
- package/build/modern/QueryClientProvider.d.ts.map +1 -1
- package/build/modern/QueryClientProvider.js +30 -0
- package/build/modern/QueryClientProvider.js.map +1 -1
- package/build/modern/QueryErrorResetBoundary.cjs +75 -0
- package/build/modern/QueryErrorResetBoundary.cjs.map +1 -1
- package/build/modern/QueryErrorResetBoundary.d.cts +106 -0
- package/build/modern/QueryErrorResetBoundary.d.cts.map +1 -1
- package/build/modern/QueryErrorResetBoundary.d.ts +106 -0
- package/build/modern/QueryErrorResetBoundary.d.ts.map +1 -1
- package/build/modern/QueryErrorResetBoundary.js +75 -0
- package/build/modern/QueryErrorResetBoundary.js.map +1 -1
- package/build/modern/infiniteQueryOptions.cjs.map +1 -1
- package/build/modern/infiniteQueryOptions.d.cts +187 -0
- package/build/modern/infiniteQueryOptions.d.cts.map +1 -1
- package/build/modern/infiniteQueryOptions.d.ts +187 -0
- package/build/modern/infiniteQueryOptions.d.ts.map +1 -1
- package/build/modern/infiniteQueryOptions.js.map +1 -1
- package/build/modern/mutationOptions.cjs.map +1 -1
- package/build/modern/mutationOptions.d.cts +68 -0
- package/build/modern/mutationOptions.d.cts.map +1 -1
- package/build/modern/mutationOptions.d.ts +68 -0
- package/build/modern/mutationOptions.d.ts.map +1 -1
- package/build/modern/mutationOptions.js.map +1 -1
- package/build/modern/queryOptions.cjs.map +1 -1
- package/build/modern/queryOptions.d.cts +198 -0
- package/build/modern/queryOptions.d.cts.map +1 -1
- package/build/modern/queryOptions.d.ts +198 -0
- package/build/modern/queryOptions.d.ts.map +1 -1
- package/build/modern/queryOptions.js.map +1 -1
- package/build/modern/types.cjs.map +1 -1
- package/build/modern/types.d.cts +228 -2
- package/build/modern/types.d.cts.map +1 -1
- package/build/modern/types.d.ts +228 -2
- package/build/modern/types.d.ts.map +1 -1
- package/build/modern/types.js.map +1 -1
- package/build/modern/useInfiniteQuery.cjs.map +1 -1
- package/build/modern/useInfiniteQuery.d.cts +116 -0
- package/build/modern/useInfiniteQuery.d.cts.map +1 -1
- package/build/modern/useInfiniteQuery.d.ts +116 -0
- package/build/modern/useInfiniteQuery.d.ts.map +1 -1
- package/build/modern/useInfiniteQuery.js.map +1 -1
- package/build/modern/useIsFetching.cjs +20 -0
- package/build/modern/useIsFetching.cjs.map +1 -1
- package/build/modern/useIsFetching.d.cts +20 -0
- package/build/modern/useIsFetching.d.cts.map +1 -1
- package/build/modern/useIsFetching.d.ts +20 -0
- package/build/modern/useIsFetching.d.ts.map +1 -1
- package/build/modern/useIsFetching.js +20 -0
- package/build/modern/useIsFetching.js.map +1 -1
- package/build/modern/useMutation.cjs +67 -0
- package/build/modern/useMutation.cjs.map +1 -1
- package/build/modern/useMutation.d.cts +67 -0
- package/build/modern/useMutation.d.cts.map +1 -1
- package/build/modern/useMutation.d.ts +67 -0
- package/build/modern/useMutation.d.ts.map +1 -1
- package/build/modern/useMutation.js +67 -0
- package/build/modern/useMutation.js.map +1 -1
- package/build/modern/useMutationState.cjs +74 -0
- package/build/modern/useMutationState.cjs.map +1 -1
- package/build/modern/useMutationState.d.cts +74 -0
- package/build/modern/useMutationState.d.cts.map +1 -1
- package/build/modern/useMutationState.d.ts +74 -0
- package/build/modern/useMutationState.d.ts.map +1 -1
- package/build/modern/useMutationState.js +74 -0
- package/build/modern/useMutationState.js.map +1 -1
- package/build/modern/usePrefetchInfiniteQuery.cjs +44 -0
- package/build/modern/usePrefetchInfiniteQuery.cjs.map +1 -1
- package/build/modern/usePrefetchInfiniteQuery.d.cts +44 -0
- package/build/modern/usePrefetchInfiniteQuery.d.cts.map +1 -1
- package/build/modern/usePrefetchInfiniteQuery.d.ts +44 -0
- package/build/modern/usePrefetchInfiniteQuery.d.ts.map +1 -1
- package/build/modern/usePrefetchInfiniteQuery.js +44 -0
- package/build/modern/usePrefetchInfiniteQuery.js.map +1 -1
- package/build/modern/usePrefetchQuery.cjs +36 -1
- package/build/modern/usePrefetchQuery.cjs.map +1 -1
- package/build/modern/usePrefetchQuery.d.cts +35 -0
- package/build/modern/usePrefetchQuery.d.cts.map +1 -1
- package/build/modern/usePrefetchQuery.d.ts +35 -0
- package/build/modern/usePrefetchQuery.d.ts.map +1 -1
- package/build/modern/usePrefetchQuery.js +36 -1
- package/build/modern/usePrefetchQuery.js.map +1 -1
- package/build/modern/useQueries.cjs +50 -0
- package/build/modern/useQueries.cjs.map +1 -1
- package/build/modern/useQueries.d.cts +85 -2
- package/build/modern/useQueries.d.cts.map +1 -1
- package/build/modern/useQueries.d.ts +85 -2
- package/build/modern/useQueries.d.ts.map +1 -1
- package/build/modern/useQueries.js +50 -0
- package/build/modern/useQueries.js.map +1 -1
- package/build/modern/useQuery.cjs.map +1 -1
- package/build/modern/useQuery.d.cts +134 -0
- package/build/modern/useQuery.d.cts.map +1 -1
- package/build/modern/useQuery.d.ts +134 -0
- package/build/modern/useQuery.d.ts.map +1 -1
- package/build/modern/useQuery.js.map +1 -1
- package/build/modern/useSuspenseInfiniteQuery.cjs +48 -0
- package/build/modern/useSuspenseInfiniteQuery.cjs.map +1 -1
- package/build/modern/useSuspenseInfiniteQuery.d.cts +48 -0
- package/build/modern/useSuspenseInfiniteQuery.d.cts.map +1 -1
- package/build/modern/useSuspenseInfiniteQuery.d.ts +48 -0
- package/build/modern/useSuspenseInfiniteQuery.d.ts.map +1 -1
- package/build/modern/useSuspenseInfiniteQuery.js +48 -0
- package/build/modern/useSuspenseInfiniteQuery.js.map +1 -1
- package/build/modern/useSuspenseQueries.cjs.map +1 -1
- package/build/modern/useSuspenseQueries.d.cts +128 -2
- package/build/modern/useSuspenseQueries.d.cts.map +1 -1
- package/build/modern/useSuspenseQueries.d.ts +128 -2
- package/build/modern/useSuspenseQueries.d.ts.map +1 -1
- package/build/modern/useSuspenseQueries.js.map +1 -1
- package/build/modern/useSuspenseQuery.cjs +43 -0
- package/build/modern/useSuspenseQuery.cjs.map +1 -1
- package/build/modern/useSuspenseQuery.d.cts +43 -0
- package/build/modern/useSuspenseQuery.d.cts.map +1 -1
- package/build/modern/useSuspenseQuery.d.ts +43 -0
- package/build/modern/useSuspenseQuery.d.ts.map +1 -1
- package/build/modern/useSuspenseQuery.js +43 -0
- package/build/modern/useSuspenseQuery.js.map +1 -1
- package/build/modern/utils.cjs.map +1 -1
- package/build/modern/utils.d.cts.map +1 -1
- package/build/modern/utils.d.ts.map +1 -1
- package/build/modern/utils.js.map +1 -1
- package/package.json +3 -3
- package/src/HydrationBoundary.tsx +61 -1
- package/src/IsRestoringProvider.ts +12 -0
- package/src/QueryClientProvider.tsx +41 -0
- package/src/QueryErrorResetBoundary.tsx +109 -0
- package/src/infiniteQueryOptions.ts +187 -0
- package/src/mutationOptions.ts +68 -0
- package/src/queryOptions.ts +198 -0
- package/src/types.ts +228 -2
- package/src/useInfiniteQuery.ts +116 -0
- package/src/useIsFetching.ts +20 -0
- package/src/useMutation.ts +67 -0
- package/src/useMutationState.ts +74 -0
- package/src/usePrefetchInfiniteQuery.tsx +44 -0
- package/src/usePrefetchQuery.tsx +36 -1
- package/src/useQueries.ts +85 -2
- package/src/useQuery.ts +134 -0
- package/src/useSuspenseInfiniteQuery.ts +48 -0
- package/src/useSuspenseQueries.ts +128 -2
- package/src/useSuspenseQuery.ts +43 -0
- package/src/utils.ts +0 -1
package/src/queryOptions.ts
CHANGED
|
@@ -11,18 +11,43 @@ import type {
|
|
|
11
11
|
|
|
12
12
|
import type { UseQueryOptions } from './types'
|
|
13
13
|
|
|
14
|
+
/**
|
|
15
|
+
* The options accepted by the `queryOptions` overload selected when no `initialData` is set — `data` may be
|
|
16
|
+
* `undefined` while the query is `pending`.
|
|
17
|
+
*
|
|
18
|
+
* @template TQueryFnData - The type your `queryFn` resolves to.
|
|
19
|
+
* @template TError - The type of errors your `queryFn` may throw.
|
|
20
|
+
* @template TData - The type `data` ends up as after `select` runs.
|
|
21
|
+
* @template TQueryKey - The type of your `queryKey`.
|
|
22
|
+
*/
|
|
14
23
|
export type UndefinedInitialDataOptions<
|
|
15
24
|
TQueryFnData = unknown,
|
|
16
25
|
TError = DefaultError,
|
|
17
26
|
TData = TQueryFnData,
|
|
18
27
|
TQueryKey extends QueryKey = QueryKey,
|
|
19
28
|
> = UseQueryOptions<TQueryFnData, TError, TData, TQueryKey> & {
|
|
29
|
+
/**
|
|
30
|
+
* If set, this value will be used as the initial data for the query cache (as long as the query hasn't been
|
|
31
|
+
* created or cached yet). If set to a function, the function will be called **once** during the shared/root
|
|
32
|
+
* query initialization, and be expected to synchronously return the initial data. Initial data is
|
|
33
|
+
* considered stale by default unless a `staleTime` has been set. `initialData` **is persisted** to the
|
|
34
|
+
* cache.
|
|
35
|
+
*/
|
|
20
36
|
initialData?:
|
|
21
37
|
| undefined
|
|
22
38
|
| InitialDataFunction<NonUndefinedGuard<TQueryFnData>>
|
|
23
39
|
| NonUndefinedGuard<TQueryFnData>
|
|
24
40
|
}
|
|
25
41
|
|
|
42
|
+
/**
|
|
43
|
+
* The options accepted by the `queryOptions` overload selected when no `initialData` is set and `queryFn` is
|
|
44
|
+
* not `skipToken` — same as {@link UndefinedInitialDataOptions}, but `queryFn` may not be `skipToken`.
|
|
45
|
+
*
|
|
46
|
+
* @template TQueryFnData - The type your `queryFn` resolves to.
|
|
47
|
+
* @template TError - The type of errors your `queryFn` may throw.
|
|
48
|
+
* @template TData - The type `data` ends up as after `select` runs.
|
|
49
|
+
* @template TQueryKey - The type of your `queryKey`.
|
|
50
|
+
*/
|
|
26
51
|
export type UnusedSkipTokenOptions<
|
|
27
52
|
TQueryFnData = unknown,
|
|
28
53
|
TError = DefaultError,
|
|
@@ -32,24 +57,77 @@ export type UnusedSkipTokenOptions<
|
|
|
32
57
|
UseQueryOptions<TQueryFnData, TError, TData, TQueryKey>,
|
|
33
58
|
'queryFn'
|
|
34
59
|
> & {
|
|
60
|
+
/**
|
|
61
|
+
* `skipToken` is not allowed as a value here — this overload is selected when no `initialData` is set. If
|
|
62
|
+
* you don't intend to run the query yet, omit `queryFn` or use a default query function instead.
|
|
63
|
+
*/
|
|
35
64
|
queryFn?: Exclude<
|
|
36
65
|
UseQueryOptions<TQueryFnData, TError, TData, TQueryKey>['queryFn'],
|
|
37
66
|
SkipToken | undefined
|
|
38
67
|
>
|
|
39
68
|
}
|
|
40
69
|
|
|
70
|
+
/**
|
|
71
|
+
* The options accepted by the `queryOptions` overload selected when `initialData` is set — `data` is never
|
|
72
|
+
* `undefined`.
|
|
73
|
+
*
|
|
74
|
+
* @template TQueryFnData - The type your `queryFn` resolves to.
|
|
75
|
+
* @template TError - The type of errors your `queryFn` may throw.
|
|
76
|
+
* @template TData - The type `data` ends up as after `select` runs.
|
|
77
|
+
* @template TQueryKey - The type of your `queryKey`.
|
|
78
|
+
*/
|
|
41
79
|
export type DefinedInitialDataOptions<
|
|
42
80
|
TQueryFnData = unknown,
|
|
43
81
|
TError = DefaultError,
|
|
44
82
|
TData = TQueryFnData,
|
|
45
83
|
TQueryKey extends QueryKey = QueryKey,
|
|
46
84
|
> = Omit<UseQueryOptions<TQueryFnData, TError, TData, TQueryKey>, 'queryFn'> & {
|
|
85
|
+
/**
|
|
86
|
+
* If set, this value will be used as the initial data for the query cache (as long as the query hasn't been
|
|
87
|
+
* created or cached yet). If set to a function, the function will be called **once** during the shared/root
|
|
88
|
+
* query initialization, and be expected to synchronously return the initial data. Initial data is
|
|
89
|
+
* considered stale by default unless a `staleTime` has been set. `initialData` **is persisted** to the
|
|
90
|
+
* cache.
|
|
91
|
+
*/
|
|
47
92
|
initialData:
|
|
48
93
|
| NonUndefinedGuard<TQueryFnData>
|
|
49
94
|
| (() => NonUndefinedGuard<TQueryFnData>)
|
|
95
|
+
/**
|
|
96
|
+
* Optional here, but omitting it is only safe when no fetch will be attempted — for example with
|
|
97
|
+
* `enabled: false`, or when a default query function has been defined. Otherwise, an enabled query with no
|
|
98
|
+
* `queryFn` still tries to fetch and fails with a "Missing queryFn" error; `initialData` does not prevent this.
|
|
99
|
+
*/
|
|
50
100
|
queryFn?: QueryFunction<TQueryFnData, TQueryKey>
|
|
51
101
|
}
|
|
52
102
|
|
|
103
|
+
/**
|
|
104
|
+
* You can generally pass everything to `queryOptions` that you can also pass to `useQuery`. These options can
|
|
105
|
+
* be shared across hooks and imperative APIs such as `queryClient.query`. `options.queryKey` is required and
|
|
106
|
+
* is the query key to generate options for.
|
|
107
|
+
*
|
|
108
|
+
* This overload is selected when `initialData` is set, so the resulting `data` is never `undefined`.
|
|
109
|
+
*
|
|
110
|
+
* @see {@link useQuery} to run a query with these options.
|
|
111
|
+
* @param options - The {@link DefinedInitialDataOptions} to use — everything you can pass to `useQuery`, with `initialData` set.
|
|
112
|
+
* @returns The same options object, typed so that `queryKey` carries the inferred data type.
|
|
113
|
+
*
|
|
114
|
+
* @example
|
|
115
|
+
* ```tsx
|
|
116
|
+
* import { queryOptions, useQuery } from '@tanstack/preact-query'
|
|
117
|
+
*
|
|
118
|
+
* export const postsOptions = queryOptions({
|
|
119
|
+
* queryKey: ['posts'],
|
|
120
|
+
* queryFn: fetchPosts,
|
|
121
|
+
* initialData: [],
|
|
122
|
+
* })
|
|
123
|
+
*
|
|
124
|
+
* function Posts() {
|
|
125
|
+
* // `data` is `Post[]`, never `undefined`, thanks to `initialData`.
|
|
126
|
+
* const { data } = useQuery(postsOptions)
|
|
127
|
+
* return <>{data.map((post) => <p key={post.id}>{post.title}</p>)}</>
|
|
128
|
+
* }
|
|
129
|
+
* ```
|
|
130
|
+
*/
|
|
53
131
|
export function queryOptions<
|
|
54
132
|
TQueryFnData = unknown,
|
|
55
133
|
TError = DefaultError,
|
|
@@ -60,6 +138,66 @@ export function queryOptions<
|
|
|
60
138
|
): DefinedInitialDataOptions<TQueryFnData, TError, TData, TQueryKey> &
|
|
61
139
|
QueryKeyWithDataTag<TQueryKey, TQueryFnData, TError>
|
|
62
140
|
|
|
141
|
+
/**
|
|
142
|
+
* You can generally pass everything to `queryOptions` that you can also pass to `useQuery`. These options can
|
|
143
|
+
* be shared across hooks and imperative APIs such as `queryClient.query`. `options.queryKey` is required and
|
|
144
|
+
* is the query key to generate options for.
|
|
145
|
+
*
|
|
146
|
+
* @see {@link useQuery} to run a query with these options.
|
|
147
|
+
* @param options - The {@link UnusedSkipTokenOptions} to use — everything you can pass to `useQuery`.
|
|
148
|
+
* @returns The same options object, typed so that `queryKey` carries the inferred data type.
|
|
149
|
+
*
|
|
150
|
+
* @example
|
|
151
|
+
* ```tsx
|
|
152
|
+
* import { queryOptions } from '@tanstack/preact-query'
|
|
153
|
+
*
|
|
154
|
+
* export const postsOptions = queryOptions({
|
|
155
|
+
* queryKey: ['posts'],
|
|
156
|
+
* queryFn: fetchPosts,
|
|
157
|
+
* })
|
|
158
|
+
* ```
|
|
159
|
+
*
|
|
160
|
+
* @example
|
|
161
|
+
* A parameterized factory, reused across a hook and an imperative call with the same cache entry:
|
|
162
|
+
* ```tsx
|
|
163
|
+
* import { noop, queryOptions, useQuery } from '@tanstack/preact-query'
|
|
164
|
+
*
|
|
165
|
+
* export const postOptions = (id: string) =>
|
|
166
|
+
* queryOptions({
|
|
167
|
+
* queryKey: ['post', id],
|
|
168
|
+
* queryFn: () => fetchPost(id),
|
|
169
|
+
* })
|
|
170
|
+
*
|
|
171
|
+
* function Post({ id }: { id: string }) {
|
|
172
|
+
* const { data } = useQuery(postOptions(id))
|
|
173
|
+
* return <h1>{data?.title}</h1>
|
|
174
|
+
* }
|
|
175
|
+
*
|
|
176
|
+
* // Elsewhere, e.g. to warm the cache before rendering `<Post>`:
|
|
177
|
+
* queryClient.query(postOptions(id)).catch(noop)
|
|
178
|
+
* ```
|
|
179
|
+
*
|
|
180
|
+
* @example
|
|
181
|
+
* The same options object works with every API that accepts query options:
|
|
182
|
+
* ```tsx
|
|
183
|
+
* import {
|
|
184
|
+
* noop,
|
|
185
|
+
* queryOptions,
|
|
186
|
+
* useQuery,
|
|
187
|
+
* useSuspenseQuery,
|
|
188
|
+
* } from '@tanstack/preact-query'
|
|
189
|
+
*
|
|
190
|
+
* const todosOptions = queryOptions({
|
|
191
|
+
* queryKey: ['todos'],
|
|
192
|
+
* queryFn: fetchTodos,
|
|
193
|
+
* })
|
|
194
|
+
*
|
|
195
|
+
* useQuery(todosOptions)
|
|
196
|
+
* useSuspenseQuery(todosOptions)
|
|
197
|
+
* queryClient.query(todosOptions).catch(noop)
|
|
198
|
+
* queryClient.getQueryData(todosOptions.queryKey) // typed as Array<Todo> | undefined
|
|
199
|
+
* ```
|
|
200
|
+
*/
|
|
63
201
|
export function queryOptions<
|
|
64
202
|
TQueryFnData = unknown,
|
|
65
203
|
TError = DefaultError,
|
|
@@ -70,6 +208,66 @@ export function queryOptions<
|
|
|
70
208
|
): UnusedSkipTokenOptions<TQueryFnData, TError, TData, TQueryKey> &
|
|
71
209
|
QueryKeyWithDataTag<TQueryKey, TQueryFnData, TError>
|
|
72
210
|
|
|
211
|
+
/**
|
|
212
|
+
* You can generally pass everything to `queryOptions` that you can also pass to `useQuery`. These options can
|
|
213
|
+
* be shared across hooks and imperative APIs such as `queryClient.query`. `options.queryKey` is required and
|
|
214
|
+
* is the query key to generate options for.
|
|
215
|
+
*
|
|
216
|
+
* @see {@link useQuery} to run a query with these options.
|
|
217
|
+
* @param options - The {@link UndefinedInitialDataOptions} to use — everything you can pass to `useQuery`.
|
|
218
|
+
* @returns The same options object, typed so that `queryKey` carries the inferred data type.
|
|
219
|
+
*
|
|
220
|
+
* @example
|
|
221
|
+
* ```tsx
|
|
222
|
+
* import { queryOptions } from '@tanstack/preact-query'
|
|
223
|
+
*
|
|
224
|
+
* export const postsOptions = queryOptions({
|
|
225
|
+
* queryKey: ['posts'],
|
|
226
|
+
* queryFn: fetchPosts,
|
|
227
|
+
* })
|
|
228
|
+
* ```
|
|
229
|
+
*
|
|
230
|
+
* @example
|
|
231
|
+
* A parameterized factory, reused across a hook and an imperative call with the same cache entry:
|
|
232
|
+
* ```tsx
|
|
233
|
+
* import { noop, queryOptions, useQuery } from '@tanstack/preact-query'
|
|
234
|
+
*
|
|
235
|
+
* export const postOptions = (id: string) =>
|
|
236
|
+
* queryOptions({
|
|
237
|
+
* queryKey: ['post', id],
|
|
238
|
+
* queryFn: () => fetchPost(id),
|
|
239
|
+
* })
|
|
240
|
+
*
|
|
241
|
+
* function Post({ id }: { id: string }) {
|
|
242
|
+
* const { data } = useQuery(postOptions(id))
|
|
243
|
+
* return <h1>{data?.title}</h1>
|
|
244
|
+
* }
|
|
245
|
+
*
|
|
246
|
+
* // Elsewhere, e.g. to warm the cache before rendering `<Post>`:
|
|
247
|
+
* queryClient.query(postOptions(id)).catch(noop)
|
|
248
|
+
* ```
|
|
249
|
+
*
|
|
250
|
+
* @example
|
|
251
|
+
* The same options object works with every API that accepts query options:
|
|
252
|
+
* ```tsx
|
|
253
|
+
* import {
|
|
254
|
+
* noop,
|
|
255
|
+
* queryOptions,
|
|
256
|
+
* useQuery,
|
|
257
|
+
* useSuspenseQuery,
|
|
258
|
+
* } from '@tanstack/preact-query'
|
|
259
|
+
*
|
|
260
|
+
* const todosOptions = queryOptions({
|
|
261
|
+
* queryKey: ['todos'],
|
|
262
|
+
* queryFn: fetchTodos,
|
|
263
|
+
* })
|
|
264
|
+
*
|
|
265
|
+
* useQuery(todosOptions)
|
|
266
|
+
* useSuspenseQuery(todosOptions)
|
|
267
|
+
* queryClient.query(todosOptions).catch(noop)
|
|
268
|
+
* queryClient.getQueryData(todosOptions.queryKey) // typed as Array<Todo> | undefined
|
|
269
|
+
* ```
|
|
270
|
+
*/
|
|
73
271
|
export function queryOptions<
|
|
74
272
|
TQueryFnData = unknown,
|
|
75
273
|
TError = DefaultError,
|
package/src/types.ts
CHANGED
|
@@ -20,6 +20,10 @@ import type {
|
|
|
20
20
|
SkipToken,
|
|
21
21
|
} from '@tanstack/query-core'
|
|
22
22
|
|
|
23
|
+
/**
|
|
24
|
+
* {@link UseBaseQueryOptions} with all type parameters set to `any`, useful when the specific types aren't
|
|
25
|
+
* relevant, e.g. when accepting options for any query in a helper function.
|
|
26
|
+
*/
|
|
23
27
|
export type AnyUseBaseQueryOptions = UseBaseQueryOptions<
|
|
24
28
|
any,
|
|
25
29
|
any,
|
|
@@ -27,6 +31,18 @@ export type AnyUseBaseQueryOptions = UseBaseQueryOptions<
|
|
|
27
31
|
any,
|
|
28
32
|
any
|
|
29
33
|
>
|
|
34
|
+
/**
|
|
35
|
+
* The options shared by `useQuery` and `useSuspenseQuery`. Extends {@link QueryObserverOptions} from
|
|
36
|
+
* `@tanstack/query-core` with the `preact-query`-specific `subscribed` option.
|
|
37
|
+
*
|
|
38
|
+
* @template TQueryFnData - The type your `queryFn` resolves to.
|
|
39
|
+
* @template TError - The type of errors your `queryFn` may throw.
|
|
40
|
+
* @template TData - The type `data` ends up as after `select` runs. Defaults to `TQueryFnData` when no
|
|
41
|
+
* `select` is used.
|
|
42
|
+
* @template TQueryData - The type of the data actually held in the query cache — the input to `select` and
|
|
43
|
+
* `placeholderData`. Defaults to, and is usually the same as, `TQueryFnData`.
|
|
44
|
+
* @template TQueryKey - The type of your `queryKey`.
|
|
45
|
+
*/
|
|
30
46
|
export interface UseBaseQueryOptions<
|
|
31
47
|
TQueryFnData = unknown,
|
|
32
48
|
TError = DefaultError,
|
|
@@ -42,11 +58,24 @@ export interface UseBaseQueryOptions<
|
|
|
42
58
|
> {
|
|
43
59
|
/**
|
|
44
60
|
* Set this to `false` to unsubscribe this observer from updates to the query cache.
|
|
45
|
-
*
|
|
61
|
+
*
|
|
62
|
+
* @defaultValue true
|
|
46
63
|
*/
|
|
47
64
|
subscribed?: boolean
|
|
48
65
|
}
|
|
49
66
|
|
|
67
|
+
/**
|
|
68
|
+
* The options accepted by `usePrefetchQuery` — everything you can pass to `queryClient.query`, except `queryFn`
|
|
69
|
+
* is required unless a default query function has been defined.
|
|
70
|
+
*
|
|
71
|
+
* @template TQueryFnData - The type your `queryFn` resolves to.
|
|
72
|
+
* @template TError - The type of errors your `queryFn` may throw.
|
|
73
|
+
* @template TData - The type `data` ends up as after `select` runs. Defaults to `TQueryFnData` when no
|
|
74
|
+
* `select` is used.
|
|
75
|
+
* @template TQueryData - The type of the data actually held in the query cache — the input to `select` and
|
|
76
|
+
* `placeholderData`. Defaults to, and is usually the same as, `TQueryFnData`.
|
|
77
|
+
* @template TQueryKey - The type of your `queryKey`.
|
|
78
|
+
*/
|
|
50
79
|
export type UsePrefetchQueryOptions<
|
|
51
80
|
TQueryFnData = unknown,
|
|
52
81
|
TError = DefaultError,
|
|
@@ -57,6 +86,10 @@ export type UsePrefetchQueryOptions<
|
|
|
57
86
|
QueryExecuteOptions<TQueryFnData, TError, TData, TQueryData, TQueryKey>,
|
|
58
87
|
'queryFn'
|
|
59
88
|
> & {
|
|
89
|
+
/**
|
|
90
|
+
* `skipToken` is not allowed as a value here — a prefetch always needs a query function to actually run,
|
|
91
|
+
* unless a default query function has been defined.
|
|
92
|
+
*/
|
|
60
93
|
queryFn?: Exclude<
|
|
61
94
|
QueryExecuteOptions<
|
|
62
95
|
TQueryFnData,
|
|
@@ -69,6 +102,18 @@ export type UsePrefetchQueryOptions<
|
|
|
69
102
|
>
|
|
70
103
|
}
|
|
71
104
|
|
|
105
|
+
/**
|
|
106
|
+
* The options accepted by `usePrefetchInfiniteQuery` — everything you can pass to `queryClient.infiniteQuery`,
|
|
107
|
+
* except `queryFn` is required unless a default query function has been defined.
|
|
108
|
+
*
|
|
109
|
+
* @template TQueryFnData - The type of a single page, as your `queryFn` resolves it.
|
|
110
|
+
* @template TError - The type of errors your `queryFn` may throw.
|
|
111
|
+
* @template TData - The type `data` ends up as after `select` runs. Defaults to `TQueryFnData` (a single page)
|
|
112
|
+
* here, since a prefetch never reads `data` back out — this parameter only matters if you reuse these options
|
|
113
|
+
* elsewhere with `select` applied.
|
|
114
|
+
* @template TQueryKey - The type of your `queryKey`.
|
|
115
|
+
* @template TPageParam - The type of the parameter passed to `queryFn` to fetch a given page.
|
|
116
|
+
*/
|
|
72
117
|
export type UsePrefetchInfiniteQueryOptions<
|
|
73
118
|
TQueryFnData = unknown,
|
|
74
119
|
TError = DefaultError,
|
|
@@ -85,6 +130,10 @@ export type UsePrefetchInfiniteQueryOptions<
|
|
|
85
130
|
>,
|
|
86
131
|
'queryFn'
|
|
87
132
|
> & {
|
|
133
|
+
/**
|
|
134
|
+
* `skipToken` is not allowed as a value here — a prefetch always needs a query function to actually run,
|
|
135
|
+
* unless a default query function has been defined.
|
|
136
|
+
*/
|
|
88
137
|
queryFn?: Exclude<
|
|
89
138
|
InfiniteQueryExecuteOptions<
|
|
90
139
|
TQueryFnData,
|
|
@@ -97,7 +146,21 @@ export type UsePrefetchInfiniteQueryOptions<
|
|
|
97
146
|
>
|
|
98
147
|
}
|
|
99
148
|
|
|
149
|
+
/**
|
|
150
|
+
* {@link UseQueryOptions} with all type parameters set to `any`, useful when the specific types aren't
|
|
151
|
+
* relevant, e.g. when accepting options for any query in a helper function.
|
|
152
|
+
*/
|
|
100
153
|
export type AnyUseQueryOptions = UseQueryOptions<any, any, any, any>
|
|
154
|
+
/**
|
|
155
|
+
* The options accepted by `useQuery`. Same as {@link UseBaseQueryOptions}, minus `suspense` (which
|
|
156
|
+
* `preact-query` derives from which hook you call rather than exposing as an option).
|
|
157
|
+
*
|
|
158
|
+
* @template TQueryFnData - The type your `queryFn` resolves to.
|
|
159
|
+
* @template TError - The type of errors your `queryFn` may throw.
|
|
160
|
+
* @template TData - The type `data` ends up as after `select` runs. Defaults to `TQueryFnData` when no
|
|
161
|
+
* `select` is used.
|
|
162
|
+
* @template TQueryKey - The type of your `queryKey`.
|
|
163
|
+
*/
|
|
101
164
|
export interface UseQueryOptions<
|
|
102
165
|
TQueryFnData = unknown,
|
|
103
166
|
TError = DefaultError,
|
|
@@ -108,12 +171,27 @@ export interface UseQueryOptions<
|
|
|
108
171
|
'suspense'
|
|
109
172
|
> {}
|
|
110
173
|
|
|
174
|
+
/**
|
|
175
|
+
* {@link UseSuspenseQueryOptions} with all type parameters set to `any`, useful when the specific types aren't
|
|
176
|
+
* relevant, e.g. when accepting options for any query in a helper function.
|
|
177
|
+
*/
|
|
111
178
|
export type AnyUseSuspenseQueryOptions = UseSuspenseQueryOptions<
|
|
112
179
|
any,
|
|
113
180
|
any,
|
|
114
181
|
any,
|
|
115
182
|
any
|
|
116
183
|
>
|
|
184
|
+
/**
|
|
185
|
+
* The options accepted by `useSuspenseQuery`. Same as {@link UseQueryOptions}, minus `enabled`, `throwOnError`,
|
|
186
|
+
* and `placeholderData` — Suspense hooks cannot render a "disabled" or "placeholder" state, so those options
|
|
187
|
+
* don't apply.
|
|
188
|
+
*
|
|
189
|
+
* @template TQueryFnData - The type your `queryFn` resolves to.
|
|
190
|
+
* @template TError - The type of errors your `queryFn` may throw.
|
|
191
|
+
* @template TData - The type `data` ends up as after `select` runs. Defaults to `TQueryFnData` when no
|
|
192
|
+
* `select` is used.
|
|
193
|
+
* @template TQueryKey - The type of your `queryKey`.
|
|
194
|
+
*/
|
|
117
195
|
export interface UseSuspenseQueryOptions<
|
|
118
196
|
TQueryFnData = unknown,
|
|
119
197
|
TError = DefaultError,
|
|
@@ -123,12 +201,20 @@ export interface UseSuspenseQueryOptions<
|
|
|
123
201
|
UseQueryOptions<TQueryFnData, TError, TData, TQueryKey>,
|
|
124
202
|
'queryFn' | 'enabled' | 'throwOnError' | 'placeholderData'
|
|
125
203
|
> {
|
|
204
|
+
/**
|
|
205
|
+
* `skipToken` is not allowed here — Suspense hooks cannot render a "disabled" state, so a query function
|
|
206
|
+
* must always be provided, unless a default query function has been defined.
|
|
207
|
+
*/
|
|
126
208
|
queryFn?: Exclude<
|
|
127
209
|
UseQueryOptions<TQueryFnData, TError, TData, TQueryKey>['queryFn'],
|
|
128
210
|
SkipToken
|
|
129
211
|
>
|
|
130
212
|
}
|
|
131
213
|
|
|
214
|
+
/**
|
|
215
|
+
* {@link UseInfiniteQueryOptions} with all type parameters set to `any`, useful when the specific types aren't
|
|
216
|
+
* relevant, e.g. when accepting options for any query in a helper function.
|
|
217
|
+
*/
|
|
132
218
|
export type AnyUseInfiniteQueryOptions = UseInfiniteQueryOptions<
|
|
133
219
|
any,
|
|
134
220
|
any,
|
|
@@ -136,6 +222,18 @@ export type AnyUseInfiniteQueryOptions = UseInfiniteQueryOptions<
|
|
|
136
222
|
any,
|
|
137
223
|
any
|
|
138
224
|
>
|
|
225
|
+
/**
|
|
226
|
+
* The options accepted by `useInfiniteQuery`. Extends {@link InfiniteQueryObserverOptions} from
|
|
227
|
+
* `@tanstack/query-core` with the `preact-query`-specific `subscribed` option, minus `suspense` (which
|
|
228
|
+
* `preact-query` derives from which hook you call rather than exposing as an option).
|
|
229
|
+
*
|
|
230
|
+
* @template TQueryFnData - The type of a single page, as your `queryFn` resolves it.
|
|
231
|
+
* @template TError - The type of errors your `queryFn` may throw.
|
|
232
|
+
* @template TData - The type `data` ends up as after `select` runs — defaults to `InfiniteData<TQueryFnData>`,
|
|
233
|
+
* the shape of all fetched pages plus their page params.
|
|
234
|
+
* @template TQueryKey - The type of your `queryKey`.
|
|
235
|
+
* @template TPageParam - The type of the parameter passed to `queryFn` to fetch a given page.
|
|
236
|
+
*/
|
|
139
237
|
export interface UseInfiniteQueryOptions<
|
|
140
238
|
TQueryFnData = unknown,
|
|
141
239
|
TError = DefaultError,
|
|
@@ -154,13 +252,30 @@ export interface UseInfiniteQueryOptions<
|
|
|
154
252
|
> {
|
|
155
253
|
/**
|
|
156
254
|
* Set this to `false` to unsubscribe this observer from updates to the query cache.
|
|
157
|
-
*
|
|
255
|
+
*
|
|
256
|
+
* @defaultValue true
|
|
158
257
|
*/
|
|
159
258
|
subscribed?: boolean
|
|
160
259
|
}
|
|
161
260
|
|
|
261
|
+
/**
|
|
262
|
+
* {@link UseSuspenseInfiniteQueryOptions} with all type parameters set to `any`, useful when the specific types
|
|
263
|
+
* aren't relevant, e.g. when accepting options for any query in a helper function.
|
|
264
|
+
*/
|
|
162
265
|
export type AnyUseSuspenseInfiniteQueryOptions =
|
|
163
266
|
UseSuspenseInfiniteQueryOptions<any, any, any, any, any>
|
|
267
|
+
/**
|
|
268
|
+
* The options accepted by `useSuspenseInfiniteQuery`. Same as {@link UseInfiniteQueryOptions}, minus `enabled`,
|
|
269
|
+
* `throwOnError`, and `placeholderData` — Suspense hooks cannot render a "disabled" or "placeholder" state, so
|
|
270
|
+
* those options don't apply.
|
|
271
|
+
*
|
|
272
|
+
* @template TQueryFnData - The type of a single page, as your `queryFn` resolves it.
|
|
273
|
+
* @template TError - The type of errors your `queryFn` may throw.
|
|
274
|
+
* @template TData - The type `data` ends up as after `select` runs — defaults to `InfiniteData<TQueryFnData>`,
|
|
275
|
+
* the shape of all fetched pages plus their page params.
|
|
276
|
+
* @template TQueryKey - The type of your `queryKey`.
|
|
277
|
+
* @template TPageParam - The type of the parameter passed to `queryFn` to fetch a given page.
|
|
278
|
+
*/
|
|
164
279
|
export interface UseSuspenseInfiniteQueryOptions<
|
|
165
280
|
TQueryFnData = unknown,
|
|
166
281
|
TError = DefaultError,
|
|
@@ -171,6 +286,10 @@ export interface UseSuspenseInfiniteQueryOptions<
|
|
|
171
286
|
UseInfiniteQueryOptions<TQueryFnData, TError, TData, TQueryKey, TPageParam>,
|
|
172
287
|
'queryFn' | 'enabled' | 'throwOnError' | 'placeholderData'
|
|
173
288
|
> {
|
|
289
|
+
/**
|
|
290
|
+
* `skipToken` is not allowed here — Suspense hooks cannot render a "disabled" state, so a query function
|
|
291
|
+
* must always be provided, unless a default query function has been defined.
|
|
292
|
+
*/
|
|
174
293
|
queryFn?: Exclude<
|
|
175
294
|
UseInfiniteQueryOptions<
|
|
176
295
|
TQueryFnData,
|
|
@@ -183,16 +302,37 @@ export interface UseSuspenseInfiniteQueryOptions<
|
|
|
183
302
|
>
|
|
184
303
|
}
|
|
185
304
|
|
|
305
|
+
/**
|
|
306
|
+
* The result of `useQuery` when `initialData` isn't set — `data` may be `undefined` while the query is
|
|
307
|
+
* `pending`. Re-exports {@link QueryObserverResult} from `@tanstack/query-core`. `useInfiniteQuery` returns
|
|
308
|
+
* {@link UseInfiniteQueryResult} instead.
|
|
309
|
+
*
|
|
310
|
+
* @template TData - The type `data` ends up as after `select` runs.
|
|
311
|
+
* @template TError - The type of errors your `queryFn` may throw.
|
|
312
|
+
*/
|
|
186
313
|
export type UseBaseQueryResult<
|
|
187
314
|
TData = unknown,
|
|
188
315
|
TError = DefaultError,
|
|
189
316
|
> = QueryObserverResult<TData, TError>
|
|
190
317
|
|
|
318
|
+
/**
|
|
319
|
+
* The result of `useQuery`. Same as {@link UseBaseQueryResult}.
|
|
320
|
+
*
|
|
321
|
+
* @template TData - The type `data` ends up as after `select` runs.
|
|
322
|
+
* @template TError - The type of errors your `queryFn` may throw.
|
|
323
|
+
*/
|
|
191
324
|
export type UseQueryResult<
|
|
192
325
|
TData = unknown,
|
|
193
326
|
TError = DefaultError,
|
|
194
327
|
> = UseBaseQueryResult<TData, TError>
|
|
195
328
|
|
|
329
|
+
/**
|
|
330
|
+
* The result of `useSuspenseQuery`. Same as {@link DefinedUseQueryResult}, minus `isPlaceholderData` — always
|
|
331
|
+
* `false` on that type, so this drops the dead field rather than an active state.
|
|
332
|
+
*
|
|
333
|
+
* @template TData - The type `data` ends up as after `select` runs.
|
|
334
|
+
* @template TError - The type of errors your `queryFn` may throw.
|
|
335
|
+
*/
|
|
196
336
|
export type UseSuspenseQueryResult<
|
|
197
337
|
TData = unknown,
|
|
198
338
|
TError = DefaultError,
|
|
@@ -201,21 +341,50 @@ export type UseSuspenseQueryResult<
|
|
|
201
341
|
'isPlaceholderData'
|
|
202
342
|
>
|
|
203
343
|
|
|
344
|
+
/**
|
|
345
|
+
* The result of `useQuery` when `initialData` is set, or of `useSuspenseQuery` before the `isPlaceholderData`
|
|
346
|
+
* omission — `data` is never `undefined`. Re-exports {@link DefinedQueryObserverResult} from
|
|
347
|
+
* `@tanstack/query-core`.
|
|
348
|
+
*
|
|
349
|
+
* @template TData - The type `data` ends up as after `select` runs.
|
|
350
|
+
* @template TError - The type of errors your `queryFn` may throw.
|
|
351
|
+
*/
|
|
204
352
|
export type DefinedUseQueryResult<
|
|
205
353
|
TData = unknown,
|
|
206
354
|
TError = DefaultError,
|
|
207
355
|
> = DefinedQueryObserverResult<TData, TError>
|
|
208
356
|
|
|
357
|
+
/**
|
|
358
|
+
* The result of `useInfiniteQuery` when `initialData` isn't set — `data` may be `undefined` while the query is
|
|
359
|
+
* `pending`. Re-exports {@link InfiniteQueryObserverResult} from `@tanstack/query-core`.
|
|
360
|
+
*
|
|
361
|
+
* @template TData - The type `data` ends up as after `select` runs.
|
|
362
|
+
* @template TError - The type of errors your `queryFn` may throw.
|
|
363
|
+
*/
|
|
209
364
|
export type UseInfiniteQueryResult<
|
|
210
365
|
TData = unknown,
|
|
211
366
|
TError = DefaultError,
|
|
212
367
|
> = InfiniteQueryObserverResult<TData, TError>
|
|
213
368
|
|
|
369
|
+
/**
|
|
370
|
+
* The result of `useInfiniteQuery` when `initialData` is set — `data` is never `undefined`. Re-exports
|
|
371
|
+
* {@link DefinedInfiniteQueryObserverResult} from `@tanstack/query-core`.
|
|
372
|
+
*
|
|
373
|
+
* @template TData - The type `data` ends up as after `select` runs.
|
|
374
|
+
* @template TError - The type of errors your `queryFn` may throw.
|
|
375
|
+
*/
|
|
214
376
|
export type DefinedUseInfiniteQueryResult<
|
|
215
377
|
TData = unknown,
|
|
216
378
|
TError = DefaultError,
|
|
217
379
|
> = DefinedInfiniteQueryObserverResult<TData, TError>
|
|
218
380
|
|
|
381
|
+
/**
|
|
382
|
+
* The result of `useSuspenseInfiniteQuery`. Same as {@link DefinedUseInfiniteQueryResult}, minus
|
|
383
|
+
* `isPlaceholderData` — Suspense hooks never render placeholder data.
|
|
384
|
+
*
|
|
385
|
+
* @template TData - The type `data` ends up as after `select` runs.
|
|
386
|
+
* @template TError - The type of errors your `queryFn` may throw.
|
|
387
|
+
*/
|
|
219
388
|
export type UseSuspenseInfiniteQueryResult<
|
|
220
389
|
TData = unknown,
|
|
221
390
|
TError = DefaultError,
|
|
@@ -224,7 +393,21 @@ export type UseSuspenseInfiniteQueryResult<
|
|
|
224
393
|
'isPlaceholderData'
|
|
225
394
|
>
|
|
226
395
|
|
|
396
|
+
/**
|
|
397
|
+
* {@link UseMutationOptions} with all type parameters set to `any`, useful when the specific types aren't
|
|
398
|
+
* relevant, e.g. when accepting options for any mutation in a helper function.
|
|
399
|
+
*/
|
|
227
400
|
export type AnyUseMutationOptions = UseMutationOptions<any, any, any, any>
|
|
401
|
+
/**
|
|
402
|
+
* The options accepted by `useMutation`. Same as {@link MutationObserverOptions} from `@tanstack/query-core`,
|
|
403
|
+
* minus the internal `_defaulted` flag.
|
|
404
|
+
*
|
|
405
|
+
* @template TData - The type your mutation function resolves to.
|
|
406
|
+
* @template TError - The type of errors your mutation function may throw.
|
|
407
|
+
* @template TVariables - The type of the variable passed to `mutate`/`mutateAsync`.
|
|
408
|
+
* @template TOnMutateResult - The type returned by `onMutate`, passed to `onSuccess`/`onError`/`onSettled` as
|
|
409
|
+
* their `onMutateResult` parameter — useful for optimistic-update rollback data.
|
|
410
|
+
*/
|
|
228
411
|
export interface UseMutationOptions<
|
|
229
412
|
TData = unknown,
|
|
230
413
|
TError = DefaultError,
|
|
@@ -235,6 +418,17 @@ export interface UseMutationOptions<
|
|
|
235
418
|
'_defaulted'
|
|
236
419
|
> {}
|
|
237
420
|
|
|
421
|
+
/**
|
|
422
|
+
* The type of `mutate`, as returned by `useMutation`. Forwards the variables (and an optional per-call
|
|
423
|
+
* `onSuccess`/`onError`/`onSettled`) to the underlying `mutate` call. Fire-and-forget — errors are surfaced
|
|
424
|
+
* through the mutation result, not thrown.
|
|
425
|
+
*
|
|
426
|
+
* @template TData - The type your mutation function resolves to.
|
|
427
|
+
* @template TError - The type of errors your mutation function may throw.
|
|
428
|
+
* @template TVariables - The type of the variable passed to `mutate`.
|
|
429
|
+
* @template TOnMutateResult - The type returned by `onMutate`, passed to `onSuccess`/`onError`/`onSettled` as
|
|
430
|
+
* their `onMutateResult` parameter — useful for optimistic-update rollback data.
|
|
431
|
+
*/
|
|
238
432
|
export type UseMutateFunction<
|
|
239
433
|
TData = unknown,
|
|
240
434
|
TError = DefaultError,
|
|
@@ -246,6 +440,16 @@ export type UseMutateFunction<
|
|
|
246
440
|
>
|
|
247
441
|
) => void
|
|
248
442
|
|
|
443
|
+
/**
|
|
444
|
+
* The type of `mutateAsync`, as returned by `useMutation`. Similar to {@link UseMutateFunction}, but returns a
|
|
445
|
+
* promise which can be awaited.
|
|
446
|
+
*
|
|
447
|
+
* @template TData - The type your mutation function resolves to.
|
|
448
|
+
* @template TError - The type of errors your mutation function may throw.
|
|
449
|
+
* @template TVariables - The type of the variable passed to `mutateAsync`.
|
|
450
|
+
* @template TOnMutateResult - The type returned by `onMutate`, passed to `onSuccess`/`onError`/`onSettled` as
|
|
451
|
+
* their `onMutateResult` parameter — useful for optimistic-update rollback data.
|
|
452
|
+
*/
|
|
249
453
|
export type UseMutateAsyncFunction<
|
|
250
454
|
TData = unknown,
|
|
251
455
|
TError = DefaultError,
|
|
@@ -253,6 +457,16 @@ export type UseMutateAsyncFunction<
|
|
|
253
457
|
TOnMutateResult = unknown,
|
|
254
458
|
> = MutateFunction<TData, TError, TVariables, TOnMutateResult>
|
|
255
459
|
|
|
460
|
+
/**
|
|
461
|
+
* The result of `useMutation`. Same as {@link MutationObserverResult} from `@tanstack/query-core`, with
|
|
462
|
+
* `mutate` narrowed to the fire-and-forget {@link UseMutateFunction} signature, plus the added `mutateAsync`.
|
|
463
|
+
*
|
|
464
|
+
* @template TData - The type your mutation function resolves to.
|
|
465
|
+
* @template TError - The type of errors your mutation function may throw.
|
|
466
|
+
* @template TVariables - The type of the variable passed to `mutate`/`mutateAsync`.
|
|
467
|
+
* @template TOnMutateResult - The type returned by `onMutate`, passed to `onSuccess`/`onError`/`onSettled` as
|
|
468
|
+
* their `onMutateResult` parameter — useful for optimistic-update rollback data.
|
|
469
|
+
*/
|
|
256
470
|
export type UseBaseMutationResult<
|
|
257
471
|
TData = unknown,
|
|
258
472
|
TError = DefaultError,
|
|
@@ -262,6 +476,9 @@ export type UseBaseMutationResult<
|
|
|
262
476
|
MutationObserverResult<TData, TError, TVariables, TOnMutateResult>,
|
|
263
477
|
{ mutate: UseMutateFunction<TData, TError, TVariables, TOnMutateResult> }
|
|
264
478
|
> & {
|
|
479
|
+
/**
|
|
480
|
+
* Similar to `mutate`, but returns a promise which can be awaited.
|
|
481
|
+
*/
|
|
265
482
|
mutateAsync: UseMutateAsyncFunction<
|
|
266
483
|
TData,
|
|
267
484
|
TError,
|
|
@@ -270,6 +487,15 @@ export type UseBaseMutationResult<
|
|
|
270
487
|
>
|
|
271
488
|
}
|
|
272
489
|
|
|
490
|
+
/**
|
|
491
|
+
* The result of `useMutation`. Same as {@link UseBaseMutationResult}.
|
|
492
|
+
*
|
|
493
|
+
* @template TData - The type your mutation function resolves to.
|
|
494
|
+
* @template TError - The type of errors your mutation function may throw.
|
|
495
|
+
* @template TVariables - The type of the variable passed to `mutate`/`mutateAsync`.
|
|
496
|
+
* @template TOnMutateResult - The type returned by `onMutate`, passed to `onSuccess`/`onError`/`onSettled` as
|
|
497
|
+
* their `onMutateResult` parameter — useful for optimistic-update rollback data.
|
|
498
|
+
*/
|
|
273
499
|
export type UseMutationResult<
|
|
274
500
|
TData = unknown,
|
|
275
501
|
TError = DefaultError,
|