@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.
- 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 +77 -0
- package/build/legacy/QueryErrorResetBoundary.cjs.map +1 -1
- package/build/legacy/QueryErrorResetBoundary.d.cts +108 -0
- package/build/legacy/QueryErrorResetBoundary.d.cts.map +1 -1
- package/build/legacy/QueryErrorResetBoundary.d.ts +108 -0
- package/build/legacy/QueryErrorResetBoundary.d.ts.map +1 -1
- package/build/legacy/QueryErrorResetBoundary.js +77 -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 +120 -0
- package/build/legacy/useInfiniteQuery.d.cts.map +1 -1
- package/build/legacy/useInfiniteQuery.d.ts +120 -0
- package/build/legacy/useInfiniteQuery.d.ts.map +1 -1
- package/build/legacy/useInfiniteQuery.js.map +1 -1
- package/build/legacy/useIsFetching.cjs +34 -0
- package/build/legacy/useIsFetching.cjs.map +1 -1
- package/build/legacy/useIsFetching.d.cts +34 -0
- package/build/legacy/useIsFetching.d.cts.map +1 -1
- package/build/legacy/useIsFetching.d.ts +34 -0
- package/build/legacy/useIsFetching.d.ts.map +1 -1
- package/build/legacy/useIsFetching.js +34 -0
- package/build/legacy/useIsFetching.js.map +1 -1
- package/build/legacy/useMutation.cjs +170 -0
- package/build/legacy/useMutation.cjs.map +1 -1
- package/build/legacy/useMutation.d.cts +170 -0
- package/build/legacy/useMutation.d.cts.map +1 -1
- package/build/legacy/useMutation.d.ts +170 -0
- package/build/legacy/useMutation.d.ts.map +1 -1
- package/build/legacy/useMutation.js +170 -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 +35 -0
- 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 +35 -0
- 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 +186 -0
- package/build/legacy/useQuery.d.cts.map +1 -1
- package/build/legacy/useQuery.d.ts +186 -0
- package/build/legacy/useQuery.d.ts.map +1 -1
- package/build/legacy/useQuery.js.map +1 -1
- package/build/legacy/useSuspenseInfiniteQuery.cjs +56 -0
- package/build/legacy/useSuspenseInfiniteQuery.cjs.map +1 -1
- package/build/legacy/useSuspenseInfiniteQuery.d.cts +56 -0
- package/build/legacy/useSuspenseInfiniteQuery.d.cts.map +1 -1
- package/build/legacy/useSuspenseInfiniteQuery.d.ts +56 -0
- package/build/legacy/useSuspenseInfiniteQuery.d.ts.map +1 -1
- package/build/legacy/useSuspenseInfiniteQuery.js +56 -0
- package/build/legacy/useSuspenseInfiniteQuery.js.map +1 -1
- package/build/legacy/useSuspenseQueries.cjs.map +1 -1
- package/build/legacy/useSuspenseQueries.d.cts +196 -2
- package/build/legacy/useSuspenseQueries.d.cts.map +1 -1
- package/build/legacy/useSuspenseQueries.d.ts +196 -2
- package/build/legacy/useSuspenseQueries.d.ts.map +1 -1
- package/build/legacy/useSuspenseQueries.js.map +1 -1
- package/build/legacy/useSuspenseQuery.cjs +47 -0
- package/build/legacy/useSuspenseQuery.cjs.map +1 -1
- package/build/legacy/useSuspenseQuery.d.cts +47 -0
- package/build/legacy/useSuspenseQuery.d.cts.map +1 -1
- package/build/legacy/useSuspenseQuery.d.ts +47 -0
- package/build/legacy/useSuspenseQuery.d.ts.map +1 -1
- package/build/legacy/useSuspenseQuery.js +47 -0
- package/build/legacy/useSuspenseQuery.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 +77 -0
- package/build/modern/QueryErrorResetBoundary.cjs.map +1 -1
- package/build/modern/QueryErrorResetBoundary.d.cts +108 -0
- package/build/modern/QueryErrorResetBoundary.d.cts.map +1 -1
- package/build/modern/QueryErrorResetBoundary.d.ts +108 -0
- package/build/modern/QueryErrorResetBoundary.d.ts.map +1 -1
- package/build/modern/QueryErrorResetBoundary.js +77 -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 +120 -0
- package/build/modern/useInfiniteQuery.d.cts.map +1 -1
- package/build/modern/useInfiniteQuery.d.ts +120 -0
- package/build/modern/useInfiniteQuery.d.ts.map +1 -1
- package/build/modern/useInfiniteQuery.js.map +1 -1
- package/build/modern/useIsFetching.cjs +34 -0
- package/build/modern/useIsFetching.cjs.map +1 -1
- package/build/modern/useIsFetching.d.cts +34 -0
- package/build/modern/useIsFetching.d.cts.map +1 -1
- package/build/modern/useIsFetching.d.ts +34 -0
- package/build/modern/useIsFetching.d.ts.map +1 -1
- package/build/modern/useIsFetching.js +34 -0
- package/build/modern/useIsFetching.js.map +1 -1
- package/build/modern/useMutation.cjs +170 -0
- package/build/modern/useMutation.cjs.map +1 -1
- package/build/modern/useMutation.d.cts +170 -0
- package/build/modern/useMutation.d.cts.map +1 -1
- package/build/modern/useMutation.d.ts +170 -0
- package/build/modern/useMutation.d.ts.map +1 -1
- package/build/modern/useMutation.js +170 -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 +35 -0
- 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 +35 -0
- 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 +186 -0
- package/build/modern/useQuery.d.cts.map +1 -1
- package/build/modern/useQuery.d.ts +186 -0
- package/build/modern/useQuery.d.ts.map +1 -1
- package/build/modern/useQuery.js.map +1 -1
- package/build/modern/useSuspenseInfiniteQuery.cjs +56 -0
- package/build/modern/useSuspenseInfiniteQuery.cjs.map +1 -1
- package/build/modern/useSuspenseInfiniteQuery.d.cts +56 -0
- package/build/modern/useSuspenseInfiniteQuery.d.cts.map +1 -1
- package/build/modern/useSuspenseInfiniteQuery.d.ts +56 -0
- package/build/modern/useSuspenseInfiniteQuery.d.ts.map +1 -1
- package/build/modern/useSuspenseInfiniteQuery.js +56 -0
- package/build/modern/useSuspenseInfiniteQuery.js.map +1 -1
- package/build/modern/useSuspenseQueries.cjs.map +1 -1
- package/build/modern/useSuspenseQueries.d.cts +196 -2
- package/build/modern/useSuspenseQueries.d.cts.map +1 -1
- package/build/modern/useSuspenseQueries.d.ts +196 -2
- package/build/modern/useSuspenseQueries.d.ts.map +1 -1
- package/build/modern/useSuspenseQueries.js.map +1 -1
- package/build/modern/useSuspenseQuery.cjs +47 -0
- package/build/modern/useSuspenseQuery.cjs.map +1 -1
- package/build/modern/useSuspenseQuery.d.cts +47 -0
- package/build/modern/useSuspenseQuery.d.cts.map +1 -1
- package/build/modern/useSuspenseQuery.d.ts +47 -0
- package/build/modern/useSuspenseQuery.d.ts.map +1 -1
- package/build/modern/useSuspenseQuery.js +47 -0
- package/build/modern/useSuspenseQuery.js.map +1 -1
- package/package.json +3 -3
- package/src/HydrationBoundary.tsx +61 -0
- package/src/IsRestoringProvider.ts +12 -0
- package/src/QueryClientProvider.tsx +41 -0
- package/src/QueryErrorResetBoundary.tsx +111 -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 +120 -0
- package/src/useIsFetching.ts +34 -0
- package/src/useMutation.ts +170 -0
- package/src/useMutationState.ts +74 -0
- package/src/usePrefetchInfiniteQuery.tsx +44 -0
- package/src/usePrefetchQuery.tsx +35 -0
- package/src/useQueries.ts +85 -2
- package/src/useQuery.ts +186 -0
- package/src/useSuspenseInfiniteQuery.ts +56 -0
- package/src/useSuspenseQueries.ts +196 -2
- package/src/useSuspenseQuery.ts +47 -0
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,
|
package/src/useInfiniteQuery.ts
CHANGED
|
@@ -18,6 +18,40 @@ import type {
|
|
|
18
18
|
} from './types'
|
|
19
19
|
import { useBaseQuery } from './useBaseQuery'
|
|
20
20
|
|
|
21
|
+
/**
|
|
22
|
+
* The options for `useInfiniteQuery` are identical to `useQuery`, with the addition of `queryFn`,
|
|
23
|
+
* `initialPageParam`, `getNextPageParam`, `getPreviousPageParam`, and `maxPages`.
|
|
24
|
+
*
|
|
25
|
+
* This overload is selected when `initialData` is set.
|
|
26
|
+
*
|
|
27
|
+
* @remarks Keep in mind that imperative fetch calls, such as `fetchNextPage`, may interfere with the default
|
|
28
|
+
* refetch behavior, resulting in outdated data. Make sure to call these functions only in response to user
|
|
29
|
+
* actions, or add conditions like `hasNextPage && !isFetching`.
|
|
30
|
+
* @see {@link infiniteQueryOptions} to share these options between `useInfiniteQuery` and imperative APIs like `queryClient.infiniteQuery`.
|
|
31
|
+
* @param options - The {@link DefinedInitialDataInfiniteOptions} to use — everything you can pass to `useInfiniteQuery`, with `initialData` set.
|
|
32
|
+
* @param queryClient - Use this to use a custom `QueryClient`. Otherwise, the one from the nearest context will
|
|
33
|
+
* be used.
|
|
34
|
+
* @returns The same properties as `useQuery`, with the addition of `data.pages`, `data.pageParams`,
|
|
35
|
+
* `fetchNextPage`, `fetchPreviousPage`, `hasNextPage`, `hasPreviousPage`, `isFetchingNextPage`, and
|
|
36
|
+
* `isFetchingPreviousPage`.
|
|
37
|
+
*
|
|
38
|
+
* @example
|
|
39
|
+
* ```tsx
|
|
40
|
+
* import { useInfiniteQuery } from '@tanstack/preact-query'
|
|
41
|
+
*
|
|
42
|
+
* function Projects() {
|
|
43
|
+
* const { data } = useInfiniteQuery({
|
|
44
|
+
* queryKey: ['projects'],
|
|
45
|
+
* queryFn: ({ pageParam }) => fetchProjects(pageParam),
|
|
46
|
+
* initialPageParam: 0,
|
|
47
|
+
* getNextPageParam: (lastPage) => lastPage.nextId,
|
|
48
|
+
* initialData: { pages: [], pageParams: [] },
|
|
49
|
+
* })
|
|
50
|
+
*
|
|
51
|
+
* return <>{data.pages.map((page) => page.projects.map((p) => <p key={p.id}>{p.name}</p>))}</>
|
|
52
|
+
* }
|
|
53
|
+
* ```
|
|
54
|
+
*/
|
|
21
55
|
export function useInfiniteQuery<
|
|
22
56
|
TQueryFnData,
|
|
23
57
|
TError = DefaultError,
|
|
@@ -35,6 +69,49 @@ export function useInfiniteQuery<
|
|
|
35
69
|
queryClient?: QueryClient,
|
|
36
70
|
): DefinedUseInfiniteQueryResult<TData, TError>
|
|
37
71
|
|
|
72
|
+
/**
|
|
73
|
+
* The options for `useInfiniteQuery` are identical to `useQuery`, with the addition of `queryFn`,
|
|
74
|
+
* `initialPageParam`, `getNextPageParam`, `getPreviousPageParam`, and `maxPages`.
|
|
75
|
+
*
|
|
76
|
+
* @remarks Keep in mind that imperative fetch calls, such as `fetchNextPage`, may interfere with the default
|
|
77
|
+
* refetch behavior, resulting in outdated data. Make sure to call these functions only in response to user
|
|
78
|
+
* actions, or add conditions like `hasNextPage && !isFetching`.
|
|
79
|
+
* @see {@link infiniteQueryOptions} to share these options between `useInfiniteQuery` and imperative APIs like `queryClient.infiniteQuery`.
|
|
80
|
+
* @param options - The {@link UndefinedInitialDataInfiniteOptions} to use — everything you can pass to `useInfiniteQuery`.
|
|
81
|
+
* @param queryClient - Use this to use a custom `QueryClient`. Otherwise, the one from the nearest context will
|
|
82
|
+
* be used.
|
|
83
|
+
* @returns The same properties as `useQuery`, with the addition of `data.pages`, `data.pageParams`,
|
|
84
|
+
* `fetchNextPage`, `fetchPreviousPage`, `hasNextPage`, `hasPreviousPage`, `isFetchingNextPage`, and
|
|
85
|
+
* `isFetchingPreviousPage`.
|
|
86
|
+
*
|
|
87
|
+
* @example
|
|
88
|
+
* ```tsx
|
|
89
|
+
* import { useInfiniteQuery } from '@tanstack/preact-query'
|
|
90
|
+
*
|
|
91
|
+
* function Projects() {
|
|
92
|
+
* const { data, fetchNextPage, hasNextPage, isFetching, isFetchingNextPage } =
|
|
93
|
+
* useInfiniteQuery({
|
|
94
|
+
* queryKey: ['projects'],
|
|
95
|
+
* queryFn: ({ pageParam }) => fetchProjects(pageParam),
|
|
96
|
+
* initialPageParam: 0,
|
|
97
|
+
* getNextPageParam: (lastPage) => lastPage.nextId,
|
|
98
|
+
* })
|
|
99
|
+
*
|
|
100
|
+
* return (
|
|
101
|
+
* <button
|
|
102
|
+
* onClick={() => fetchNextPage()}
|
|
103
|
+
* disabled={!hasNextPage || isFetching}
|
|
104
|
+
* >
|
|
105
|
+
* {isFetchingNextPage
|
|
106
|
+
* ? 'Loading more...'
|
|
107
|
+
* : hasNextPage
|
|
108
|
+
* ? 'Load More'
|
|
109
|
+
* : 'Nothing more to load'}
|
|
110
|
+
* </button>
|
|
111
|
+
* )
|
|
112
|
+
* }
|
|
113
|
+
* ```
|
|
114
|
+
*/
|
|
38
115
|
export function useInfiniteQuery<
|
|
39
116
|
TQueryFnData,
|
|
40
117
|
TError = DefaultError,
|
|
@@ -52,6 +129,49 @@ export function useInfiniteQuery<
|
|
|
52
129
|
queryClient?: QueryClient,
|
|
53
130
|
): UseInfiniteQueryResult<TData, TError>
|
|
54
131
|
|
|
132
|
+
/**
|
|
133
|
+
* The options for `useInfiniteQuery` are identical to `useQuery`, with the addition of `queryFn`,
|
|
134
|
+
* `initialPageParam`, `getNextPageParam`, `getPreviousPageParam`, and `maxPages`.
|
|
135
|
+
*
|
|
136
|
+
* @remarks Keep in mind that imperative fetch calls, such as `fetchNextPage`, may interfere with the default
|
|
137
|
+
* refetch behavior, resulting in outdated data. Make sure to call these functions only in response to user
|
|
138
|
+
* actions, or add conditions like `hasNextPage && !isFetching`.
|
|
139
|
+
* @see {@link infiniteQueryOptions} to share these options between `useInfiniteQuery` and imperative APIs like `queryClient.infiniteQuery`.
|
|
140
|
+
* @param options - The {@link UseInfiniteQueryOptions} to use — everything you can pass to `useInfiniteQuery`.
|
|
141
|
+
* @param queryClient - Use this to use a custom `QueryClient`. Otherwise, the one from the nearest context will
|
|
142
|
+
* be used.
|
|
143
|
+
* @returns The same properties as `useQuery`, with the addition of `data.pages`, `data.pageParams`,
|
|
144
|
+
* `fetchNextPage`, `fetchPreviousPage`, `hasNextPage`, `hasPreviousPage`, `isFetchingNextPage`, and
|
|
145
|
+
* `isFetchingPreviousPage`.
|
|
146
|
+
*
|
|
147
|
+
* @example
|
|
148
|
+
* ```tsx
|
|
149
|
+
* import { useInfiniteQuery } from '@tanstack/preact-query'
|
|
150
|
+
*
|
|
151
|
+
* function Projects() {
|
|
152
|
+
* const { data, fetchNextPage, hasNextPage, isFetching, isFetchingNextPage } =
|
|
153
|
+
* useInfiniteQuery({
|
|
154
|
+
* queryKey: ['projects'],
|
|
155
|
+
* queryFn: ({ pageParam }) => fetchProjects(pageParam),
|
|
156
|
+
* initialPageParam: 0,
|
|
157
|
+
* getNextPageParam: (lastPage) => lastPage.nextId,
|
|
158
|
+
* })
|
|
159
|
+
*
|
|
160
|
+
* return (
|
|
161
|
+
* <button
|
|
162
|
+
* onClick={() => fetchNextPage()}
|
|
163
|
+
* disabled={!hasNextPage || isFetching}
|
|
164
|
+
* >
|
|
165
|
+
* {isFetchingNextPage
|
|
166
|
+
* ? 'Loading more...'
|
|
167
|
+
* : hasNextPage
|
|
168
|
+
* ? 'Load More'
|
|
169
|
+
* : 'Nothing more to load'}
|
|
170
|
+
* </button>
|
|
171
|
+
* )
|
|
172
|
+
* }
|
|
173
|
+
* ```
|
|
174
|
+
*/
|
|
55
175
|
export function useInfiniteQuery<
|
|
56
176
|
TQueryFnData,
|
|
57
177
|
TError = DefaultError,
|
package/src/useIsFetching.ts
CHANGED
|
@@ -5,6 +5,40 @@ import { useCallback } from 'preact/hooks'
|
|
|
5
5
|
import { useQueryClient } from './QueryClientProvider'
|
|
6
6
|
import { useSyncExternalStore } from './utils'
|
|
7
7
|
|
|
8
|
+
/**
|
|
9
|
+
* `useIsFetching` is an optional hook that returns the `number` of the queries that your application is loading or
|
|
10
|
+
* fetching in the background (useful for app-wide loading indicators).
|
|
11
|
+
*
|
|
12
|
+
* @param filters - The {@link QueryFilters} to narrow down the matched queries.
|
|
13
|
+
* @param queryClient - Use this to use a custom `QueryClient`. Otherwise, the one from the nearest context will
|
|
14
|
+
* be used.
|
|
15
|
+
* @returns Will be the `number` of the queries that your application is currently loading or fetching in the
|
|
16
|
+
* background.
|
|
17
|
+
*
|
|
18
|
+
* @example
|
|
19
|
+
* ```tsx
|
|
20
|
+
* import { useIsFetching } from '@tanstack/preact-query'
|
|
21
|
+
*
|
|
22
|
+
* // How many queries are fetching?
|
|
23
|
+
* const isFetching = useIsFetching()
|
|
24
|
+
* // How many queries matching the posts prefix are fetching?
|
|
25
|
+
* const isFetchingPosts = useIsFetching({ queryKey: ['posts'] })
|
|
26
|
+
* ```
|
|
27
|
+
*
|
|
28
|
+
* @example
|
|
29
|
+
* A global loading indicator for any query fetching in the background, not just the ones on screen:
|
|
30
|
+
* ```tsx
|
|
31
|
+
* import { useIsFetching } from '@tanstack/preact-query'
|
|
32
|
+
*
|
|
33
|
+
* function GlobalLoadingIndicator() {
|
|
34
|
+
* const isFetching = useIsFetching()
|
|
35
|
+
*
|
|
36
|
+
* return isFetching ? (
|
|
37
|
+
* <div>Queries are fetching in the background...</div>
|
|
38
|
+
* ) : null
|
|
39
|
+
* }
|
|
40
|
+
* ```
|
|
41
|
+
*/
|
|
8
42
|
export function useIsFetching(
|
|
9
43
|
filters?: QueryFilters,
|
|
10
44
|
queryClient?: QueryClient,
|