@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
|
@@ -11,6 +11,17 @@ import type {
|
|
|
11
11
|
|
|
12
12
|
import type { UseInfiniteQueryOptions } from './types'
|
|
13
13
|
|
|
14
|
+
/**
|
|
15
|
+
* The options accepted by the `infiniteQueryOptions` overload selected when no `initialData` is set — `data`
|
|
16
|
+
* may be `undefined` while the query is `pending`.
|
|
17
|
+
*
|
|
18
|
+
* @template TQueryFnData - The type of a single page, as your `queryFn` resolves it.
|
|
19
|
+
* @template TError - The type of errors your `queryFn` may throw.
|
|
20
|
+
* @template TData - The type `data` ends up as after `select` runs — defaults to `InfiniteData<TQueryFnData>`,
|
|
21
|
+
* the shape of all fetched pages plus their page params.
|
|
22
|
+
* @template TQueryKey - The type of your `queryKey`.
|
|
23
|
+
* @template TPageParam - The type of the parameter passed to `queryFn` to fetch a given page.
|
|
24
|
+
*/
|
|
14
25
|
export type UndefinedInitialDataInfiniteOptions<
|
|
15
26
|
TQueryFnData,
|
|
16
27
|
TError = DefaultError,
|
|
@@ -24,6 +35,13 @@ export type UndefinedInitialDataInfiniteOptions<
|
|
|
24
35
|
TQueryKey,
|
|
25
36
|
TPageParam
|
|
26
37
|
> & {
|
|
38
|
+
/**
|
|
39
|
+
* If set, this value will be used as the initial data for the query cache (as long as the query hasn't been
|
|
40
|
+
* created or cached yet). If set to a function, the function will be called **once** during the shared/root
|
|
41
|
+
* query initialization, and be expected to synchronously return the initial data. Initial data is
|
|
42
|
+
* considered stale by default unless a `staleTime` has been set. `initialData` **is persisted** to the
|
|
43
|
+
* cache.
|
|
44
|
+
*/
|
|
27
45
|
initialData?:
|
|
28
46
|
| undefined
|
|
29
47
|
| NonUndefinedGuard<InfiniteData<TQueryFnData, TPageParam>>
|
|
@@ -32,6 +50,18 @@ export type UndefinedInitialDataInfiniteOptions<
|
|
|
32
50
|
>
|
|
33
51
|
}
|
|
34
52
|
|
|
53
|
+
/**
|
|
54
|
+
* The options accepted by the `infiniteQueryOptions` overload selected when no `initialData` is set and
|
|
55
|
+
* `queryFn` is not `skipToken` — same as {@link UndefinedInitialDataInfiniteOptions}, but `queryFn` may not be
|
|
56
|
+
* `skipToken`.
|
|
57
|
+
*
|
|
58
|
+
* @template TQueryFnData - The type of a single page, as your `queryFn` resolves it.
|
|
59
|
+
* @template TError - The type of errors your `queryFn` may throw.
|
|
60
|
+
* @template TData - The type `data` ends up as after `select` runs — defaults to `InfiniteData<TQueryFnData>`,
|
|
61
|
+
* the shape of all fetched pages plus their page params.
|
|
62
|
+
* @template TQueryKey - The type of your `queryKey`.
|
|
63
|
+
* @template TPageParam - The type of the parameter passed to `queryFn` to fetch a given page.
|
|
64
|
+
*/
|
|
35
65
|
export type UnusedSkipTokenInfiniteOptions<
|
|
36
66
|
TQueryFnData,
|
|
37
67
|
TError = DefaultError,
|
|
@@ -42,6 +72,10 @@ export type UnusedSkipTokenInfiniteOptions<
|
|
|
42
72
|
UseInfiniteQueryOptions<TQueryFnData, TError, TData, TQueryKey, TPageParam>,
|
|
43
73
|
'queryFn'
|
|
44
74
|
> & {
|
|
75
|
+
/**
|
|
76
|
+
* `skipToken` is not allowed as a value here — this overload is selected when no `initialData` is set. If
|
|
77
|
+
* you don't intend to run the query yet, omit `queryFn` or use a default query function instead.
|
|
78
|
+
*/
|
|
45
79
|
queryFn?: Exclude<
|
|
46
80
|
UseInfiniteQueryOptions<
|
|
47
81
|
TQueryFnData,
|
|
@@ -54,6 +88,17 @@ export type UnusedSkipTokenInfiniteOptions<
|
|
|
54
88
|
>
|
|
55
89
|
}
|
|
56
90
|
|
|
91
|
+
/**
|
|
92
|
+
* The options accepted by the `infiniteQueryOptions` overload selected when `initialData` is set — `data` is
|
|
93
|
+
* never `undefined`.
|
|
94
|
+
*
|
|
95
|
+
* @template TQueryFnData - The type of a single page, as your `queryFn` resolves it.
|
|
96
|
+
* @template TError - The type of errors your `queryFn` may throw.
|
|
97
|
+
* @template TData - The type `data` ends up as after `select` runs — defaults to `InfiniteData<TQueryFnData>`,
|
|
98
|
+
* the shape of all fetched pages plus their page params.
|
|
99
|
+
* @template TQueryKey - The type of your `queryKey`.
|
|
100
|
+
* @template TPageParam - The type of the parameter passed to `queryFn` to fetch a given page.
|
|
101
|
+
*/
|
|
57
102
|
export type DefinedInitialDataInfiniteOptions<
|
|
58
103
|
TQueryFnData,
|
|
59
104
|
TError = DefaultError,
|
|
@@ -67,12 +112,48 @@ export type DefinedInitialDataInfiniteOptions<
|
|
|
67
112
|
TQueryKey,
|
|
68
113
|
TPageParam
|
|
69
114
|
> & {
|
|
115
|
+
/**
|
|
116
|
+
* If set, this value will be used as the initial data for the query cache (as long as the query hasn't been
|
|
117
|
+
* created or cached yet). If set to a function, the function will be called **once** during the shared/root
|
|
118
|
+
* query initialization, and be expected to synchronously return the initial data. Initial data is
|
|
119
|
+
* considered stale by default unless a `staleTime` has been set. `initialData` **is persisted** to the
|
|
120
|
+
* cache.
|
|
121
|
+
*/
|
|
70
122
|
initialData:
|
|
71
123
|
| NonUndefinedGuard<InfiniteData<TQueryFnData, TPageParam>>
|
|
72
124
|
| (() => NonUndefinedGuard<InfiniteData<TQueryFnData, TPageParam>>)
|
|
73
125
|
| undefined
|
|
74
126
|
}
|
|
75
127
|
|
|
128
|
+
/**
|
|
129
|
+
* You can generally pass everything to `infiniteQueryOptions` that you can also pass to `useInfiniteQuery`.
|
|
130
|
+
* These options can be shared across hooks and imperative APIs such as `queryClient.infiniteQuery`.
|
|
131
|
+
* `options.queryKey` is required and is the query key to generate options for.
|
|
132
|
+
*
|
|
133
|
+
* This overload is selected when `initialData` is set.
|
|
134
|
+
*
|
|
135
|
+
* @see {@link useInfiniteQuery} to run an infinite query with these options.
|
|
136
|
+
* @param options - The {@link DefinedInitialDataInfiniteOptions} to use — everything you can pass to `useInfiniteQuery`, with `initialData` set.
|
|
137
|
+
* @returns The same options object, typed so that `queryKey` carries the inferred data type.
|
|
138
|
+
*
|
|
139
|
+
* @example
|
|
140
|
+
* ```tsx
|
|
141
|
+
* import { infiniteQueryOptions, useInfiniteQuery } from '@tanstack/preact-query'
|
|
142
|
+
*
|
|
143
|
+
* export const projectsOptions = infiniteQueryOptions({
|
|
144
|
+
* queryKey: ['projects'],
|
|
145
|
+
* queryFn: ({ pageParam }) => fetchProjects(pageParam),
|
|
146
|
+
* initialPageParam: 0,
|
|
147
|
+
* getNextPageParam: (lastPage) => lastPage.nextId,
|
|
148
|
+
* initialData: { pages: [], pageParams: [] },
|
|
149
|
+
* })
|
|
150
|
+
*
|
|
151
|
+
* function Projects() {
|
|
152
|
+
* const { data } = useInfiniteQuery(projectsOptions)
|
|
153
|
+
* return <>{data.pages.map((page) => page.projects.map((p) => <p key={p.id}>{p.name}</p>))}</>
|
|
154
|
+
* }
|
|
155
|
+
* ```
|
|
156
|
+
*/
|
|
76
157
|
export function infiniteQueryOptions<
|
|
77
158
|
TQueryFnData,
|
|
78
159
|
TError = DefaultError,
|
|
@@ -96,6 +177,59 @@ export function infiniteQueryOptions<
|
|
|
96
177
|
> &
|
|
97
178
|
QueryKeyWithDataTag<TQueryKey, InfiniteData<TQueryFnData>, TError>
|
|
98
179
|
|
|
180
|
+
/**
|
|
181
|
+
* You can generally pass everything to `infiniteQueryOptions` that you can also pass to `useInfiniteQuery`.
|
|
182
|
+
* These options can be shared across hooks and imperative APIs such as `queryClient.infiniteQuery`.
|
|
183
|
+
* `options.queryKey` is required and is the query key to generate options for.
|
|
184
|
+
*
|
|
185
|
+
* @returns The same options object, typed so that `queryKey` carries the inferred data type.
|
|
186
|
+
*
|
|
187
|
+
* @example
|
|
188
|
+
* ```tsx
|
|
189
|
+
* import { infiniteQueryOptions } from '@tanstack/preact-query'
|
|
190
|
+
*
|
|
191
|
+
* export const projectsOptions = infiniteQueryOptions({
|
|
192
|
+
* queryKey: ['projects'],
|
|
193
|
+
* queryFn: ({ pageParam }) => fetchProjects(pageParam),
|
|
194
|
+
* initialPageParam: 0,
|
|
195
|
+
* getNextPageParam: (lastPage) => lastPage.nextId,
|
|
196
|
+
* })
|
|
197
|
+
* ```
|
|
198
|
+
*
|
|
199
|
+
* @example
|
|
200
|
+
* A parameterized factory, reused across a hook and an imperative call with the same cache entry:
|
|
201
|
+
* ```tsx
|
|
202
|
+
* import {
|
|
203
|
+
* infiniteQueryOptions,
|
|
204
|
+
* noop,
|
|
205
|
+
* useInfiniteQuery,
|
|
206
|
+
* } from '@tanstack/preact-query'
|
|
207
|
+
*
|
|
208
|
+
* export const commentsOptions = (postId: string) =>
|
|
209
|
+
* infiniteQueryOptions({
|
|
210
|
+
* queryKey: ['post', postId, 'comments'],
|
|
211
|
+
* queryFn: ({ pageParam }) => fetchComments(postId, pageParam),
|
|
212
|
+
* initialPageParam: 0,
|
|
213
|
+
* getNextPageParam: (lastPage) => lastPage.nextId,
|
|
214
|
+
* })
|
|
215
|
+
*
|
|
216
|
+
* function Comments({ postId }: { postId: string }) {
|
|
217
|
+
* const result = useInfiniteQuery(commentsOptions(postId))
|
|
218
|
+
* if (!result.isSuccess) return 'Loading...'
|
|
219
|
+
* return (
|
|
220
|
+
* <>
|
|
221
|
+
* {result.data.pages.map((page) => page.comments.map((c) => <p key={c.id}>{c.text}</p>))}
|
|
222
|
+
* </>
|
|
223
|
+
* )
|
|
224
|
+
* }
|
|
225
|
+
*
|
|
226
|
+
* // Elsewhere, e.g. to warm the cache before rendering `<Comments>`:
|
|
227
|
+
* queryClient.infiniteQuery(commentsOptions(postId)).catch(noop)
|
|
228
|
+
* ```
|
|
229
|
+
*
|
|
230
|
+
* @see {@link useInfiniteQuery} to run an infinite query with these options.
|
|
231
|
+
* @param options - The {@link UnusedSkipTokenInfiniteOptions} to use — everything you can pass to `useInfiniteQuery`.
|
|
232
|
+
*/
|
|
99
233
|
export function infiniteQueryOptions<
|
|
100
234
|
TQueryFnData,
|
|
101
235
|
TError = DefaultError,
|
|
@@ -119,6 +253,59 @@ export function infiniteQueryOptions<
|
|
|
119
253
|
> &
|
|
120
254
|
QueryKeyWithDataTag<TQueryKey, InfiniteData<TQueryFnData>, TError>
|
|
121
255
|
|
|
256
|
+
/**
|
|
257
|
+
* You can generally pass everything to `infiniteQueryOptions` that you can also pass to `useInfiniteQuery`.
|
|
258
|
+
* These options can be shared across hooks and imperative APIs such as `queryClient.infiniteQuery`.
|
|
259
|
+
* `options.queryKey` is required and is the query key to generate options for.
|
|
260
|
+
*
|
|
261
|
+
* @returns The same options object, typed so that `queryKey` carries the inferred data type.
|
|
262
|
+
*
|
|
263
|
+
* @example
|
|
264
|
+
* ```tsx
|
|
265
|
+
* import { infiniteQueryOptions } from '@tanstack/preact-query'
|
|
266
|
+
*
|
|
267
|
+
* export const projectsOptions = infiniteQueryOptions({
|
|
268
|
+
* queryKey: ['projects'],
|
|
269
|
+
* queryFn: ({ pageParam }) => fetchProjects(pageParam),
|
|
270
|
+
* initialPageParam: 0,
|
|
271
|
+
* getNextPageParam: (lastPage) => lastPage.nextId,
|
|
272
|
+
* })
|
|
273
|
+
* ```
|
|
274
|
+
*
|
|
275
|
+
* @example
|
|
276
|
+
* A parameterized factory, reused across a hook and an imperative call with the same cache entry:
|
|
277
|
+
* ```tsx
|
|
278
|
+
* import {
|
|
279
|
+
* infiniteQueryOptions,
|
|
280
|
+
* noop,
|
|
281
|
+
* useInfiniteQuery,
|
|
282
|
+
* } from '@tanstack/preact-query'
|
|
283
|
+
*
|
|
284
|
+
* export const commentsOptions = (postId: string) =>
|
|
285
|
+
* infiniteQueryOptions({
|
|
286
|
+
* queryKey: ['post', postId, 'comments'],
|
|
287
|
+
* queryFn: ({ pageParam }) => fetchComments(postId, pageParam),
|
|
288
|
+
* initialPageParam: 0,
|
|
289
|
+
* getNextPageParam: (lastPage) => lastPage.nextId,
|
|
290
|
+
* })
|
|
291
|
+
*
|
|
292
|
+
* function Comments({ postId }: { postId: string }) {
|
|
293
|
+
* const result = useInfiniteQuery(commentsOptions(postId))
|
|
294
|
+
* if (!result.isSuccess) return 'Loading...'
|
|
295
|
+
* return (
|
|
296
|
+
* <>
|
|
297
|
+
* {result.data.pages.map((page) => page.comments.map((c) => <p key={c.id}>{c.text}</p>))}
|
|
298
|
+
* </>
|
|
299
|
+
* )
|
|
300
|
+
* }
|
|
301
|
+
*
|
|
302
|
+
* // Elsewhere, e.g. to warm the cache before rendering `<Comments>`:
|
|
303
|
+
* queryClient.infiniteQuery(commentsOptions(postId)).catch(noop)
|
|
304
|
+
* ```
|
|
305
|
+
*
|
|
306
|
+
* @see {@link useInfiniteQuery} to run an infinite query with these options.
|
|
307
|
+
* @param options - The {@link UndefinedInitialDataInfiniteOptions} to use — everything you can pass to `useInfiniteQuery`.
|
|
308
|
+
*/
|
|
122
309
|
export function infiniteQueryOptions<
|
|
123
310
|
TQueryFnData,
|
|
124
311
|
TError = DefaultError,
|
package/src/mutationOptions.ts
CHANGED
|
@@ -2,6 +2,50 @@ import type { DefaultError, WithRequired } from '@tanstack/query-core'
|
|
|
2
2
|
|
|
3
3
|
import type { UseMutationOptions } from './types'
|
|
4
4
|
|
|
5
|
+
/**
|
|
6
|
+
* You can generally pass everything to `mutationOptions` that you can also pass to `useMutation`. A
|
|
7
|
+
* `mutationKey` is required on this overload so the mutation can be looked up later, e.g. with
|
|
8
|
+
* `useMutationState`.
|
|
9
|
+
*
|
|
10
|
+
* @see {@link useMutation} to run the mutation these options describe.
|
|
11
|
+
* @param options - The mutation options to use, identical to what you'd pass to `useMutation`, with a
|
|
12
|
+
* required `mutationKey`.
|
|
13
|
+
* @returns The same options object, unchanged.
|
|
14
|
+
*
|
|
15
|
+
* @example
|
|
16
|
+
* ```tsx
|
|
17
|
+
* import { mutationOptions, useMutation } from '@tanstack/preact-query'
|
|
18
|
+
*
|
|
19
|
+
* export const createPostOptions = mutationOptions({
|
|
20
|
+
* mutationKey: ['posts', 'create'],
|
|
21
|
+
* mutationFn: createPost,
|
|
22
|
+
* })
|
|
23
|
+
*
|
|
24
|
+
* function CreatePost() {
|
|
25
|
+
* const mutation = useMutation(createPostOptions)
|
|
26
|
+
* return <button onClick={() => mutation.mutate({ title: 'Hello' })}>Create</button>
|
|
27
|
+
* }
|
|
28
|
+
* ```
|
|
29
|
+
*
|
|
30
|
+
* @example
|
|
31
|
+
* Looking the mutation up elsewhere via its `mutationKey`, e.g. for a global "saving…" indicator:
|
|
32
|
+
* ```tsx
|
|
33
|
+
* import { mutationOptions, useMutationState } from '@tanstack/preact-query'
|
|
34
|
+
*
|
|
35
|
+
* const createPostOptions = mutationOptions({
|
|
36
|
+
* mutationKey: ['posts', 'create'],
|
|
37
|
+
* mutationFn: createPost,
|
|
38
|
+
* })
|
|
39
|
+
*
|
|
40
|
+
* function SavingIndicator() {
|
|
41
|
+
* const isCreatingPost = useMutationState({
|
|
42
|
+
* filters: { mutationKey: createPostOptions.mutationKey, status: 'pending' },
|
|
43
|
+
* }).length > 0
|
|
44
|
+
*
|
|
45
|
+
* return isCreatingPost ? <span>Saving…</span> : null
|
|
46
|
+
* }
|
|
47
|
+
* ```
|
|
48
|
+
*/
|
|
5
49
|
export function mutationOptions<
|
|
6
50
|
TData = unknown,
|
|
7
51
|
TError = DefaultError,
|
|
@@ -16,6 +60,30 @@ export function mutationOptions<
|
|
|
16
60
|
UseMutationOptions<TData, TError, TVariables, TOnMutateResult>,
|
|
17
61
|
'mutationKey'
|
|
18
62
|
>
|
|
63
|
+
/**
|
|
64
|
+
* You can generally pass everything to `mutationOptions` that you can also pass to `useMutation`. No
|
|
65
|
+
* `mutationKey` is required on this overload — use this when you don't need to look the mutation up later
|
|
66
|
+
* (e.g. with `useMutationState`).
|
|
67
|
+
*
|
|
68
|
+
* @see {@link useMutation} to run the mutation these options describe.
|
|
69
|
+
* @param options - The mutation options to use, identical to what you'd pass to `useMutation`, without a
|
|
70
|
+
* `mutationKey`.
|
|
71
|
+
* @returns The same options object, unchanged.
|
|
72
|
+
*
|
|
73
|
+
* @example
|
|
74
|
+
* ```tsx
|
|
75
|
+
* import { mutationOptions, useMutation } from '@tanstack/preact-query'
|
|
76
|
+
*
|
|
77
|
+
* export const createPostOptions = mutationOptions({
|
|
78
|
+
* mutationFn: createPost,
|
|
79
|
+
* })
|
|
80
|
+
*
|
|
81
|
+
* function CreatePost() {
|
|
82
|
+
* const mutation = useMutation(createPostOptions)
|
|
83
|
+
* return <button onClick={() => mutation.mutate({ title: 'Hello' })}>Create</button>
|
|
84
|
+
* }
|
|
85
|
+
* ```
|
|
86
|
+
*/
|
|
19
87
|
export function mutationOptions<
|
|
20
88
|
TData = unknown,
|
|
21
89
|
TError = DefaultError,
|
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,
|