@tanstack/react-query 5.102.8 → 5.103.0
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 +44 -1
- 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 +44 -1
- 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 +76 -0
- package/build/legacy/QueryErrorResetBoundary.cjs.map +1 -1
- package/build/legacy/QueryErrorResetBoundary.d.cts +77 -0
- package/build/legacy/QueryErrorResetBoundary.d.cts.map +1 -1
- package/build/legacy/QueryErrorResetBoundary.d.ts +77 -0
- package/build/legacy/QueryErrorResetBoundary.d.ts.map +1 -1
- package/build/legacy/QueryErrorResetBoundary.js +76 -0
- package/build/legacy/QueryErrorResetBoundary.js.map +1 -1
- package/build/legacy/infiniteQueryOptions.cjs.map +1 -1
- package/build/legacy/infiniteQueryOptions.d.cts +173 -0
- package/build/legacy/infiniteQueryOptions.d.cts.map +1 -1
- package/build/legacy/infiniteQueryOptions.d.ts +173 -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 +55 -0
- package/build/legacy/mutationOptions.d.cts.map +1 -1
- package/build/legacy/mutationOptions.d.ts +55 -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 +175 -0
- package/build/legacy/queryOptions.d.cts.map +1 -1
- package/build/legacy/queryOptions.d.ts +175 -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 +292 -0
- package/build/legacy/useInfiniteQuery.d.cts.map +1 -1
- package/build/legacy/useInfiniteQuery.d.ts +292 -0
- package/build/legacy/useInfiniteQuery.d.ts.map +1 -1
- package/build/legacy/useInfiniteQuery.js.map +1 -1
- package/build/legacy/useIsFetching.cjs +36 -0
- package/build/legacy/useIsFetching.cjs.map +1 -1
- package/build/legacy/useIsFetching.d.cts +36 -0
- package/build/legacy/useIsFetching.d.cts.map +1 -1
- package/build/legacy/useIsFetching.d.ts +36 -0
- package/build/legacy/useIsFetching.d.ts.map +1 -1
- package/build/legacy/useIsFetching.js +36 -0
- package/build/legacy/useIsFetching.js.map +1 -1
- package/build/legacy/useMutation.cjs +172 -0
- package/build/legacy/useMutation.cjs.map +1 -1
- package/build/legacy/useMutation.d.cts +172 -0
- package/build/legacy/useMutation.d.cts.map +1 -1
- package/build/legacy/useMutation.d.ts +172 -0
- package/build/legacy/useMutation.d.ts.map +1 -1
- package/build/legacy/useMutation.js +172 -0
- package/build/legacy/useMutation.js.map +1 -1
- package/build/legacy/useMutationState.cjs +94 -0
- package/build/legacy/useMutationState.cjs.map +1 -1
- package/build/legacy/useMutationState.d.cts +94 -0
- package/build/legacy/useMutationState.d.cts.map +1 -1
- package/build/legacy/useMutationState.d.ts +94 -0
- package/build/legacy/useMutationState.d.ts.map +1 -1
- package/build/legacy/useMutationState.js +94 -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 +130 -0
- package/build/legacy/useQueries.cjs.map +1 -1
- package/build/legacy/useQueries.d.cts +165 -2
- package/build/legacy/useQueries.d.cts.map +1 -1
- package/build/legacy/useQueries.d.ts +165 -2
- package/build/legacy/useQueries.d.ts.map +1 -1
- package/build/legacy/useQueries.js +130 -0
- package/build/legacy/useQueries.js.map +1 -1
- package/build/legacy/useQuery.cjs.map +1 -1
- package/build/legacy/useQuery.d.cts +246 -0
- package/build/legacy/useQuery.d.cts.map +1 -1
- package/build/legacy/useQuery.d.ts +246 -0
- package/build/legacy/useQuery.d.ts.map +1 -1
- package/build/legacy/useQuery.js.map +1 -1
- package/build/legacy/useSuspenseInfiniteQuery.cjs +86 -0
- package/build/legacy/useSuspenseInfiniteQuery.cjs.map +1 -1
- package/build/legacy/useSuspenseInfiniteQuery.d.cts +86 -0
- package/build/legacy/useSuspenseInfiniteQuery.d.cts.map +1 -1
- package/build/legacy/useSuspenseInfiniteQuery.d.ts +86 -0
- package/build/legacy/useSuspenseInfiniteQuery.d.ts.map +1 -1
- package/build/legacy/useSuspenseInfiniteQuery.js +86 -0
- package/build/legacy/useSuspenseInfiniteQuery.js.map +1 -1
- package/build/legacy/useSuspenseQueries.cjs.map +1 -1
- package/build/legacy/useSuspenseQueries.d.cts +320 -2
- package/build/legacy/useSuspenseQueries.d.cts.map +1 -1
- package/build/legacy/useSuspenseQueries.d.ts +320 -2
- package/build/legacy/useSuspenseQueries.d.ts.map +1 -1
- package/build/legacy/useSuspenseQueries.js.map +1 -1
- package/build/legacy/useSuspenseQuery.cjs +67 -0
- package/build/legacy/useSuspenseQuery.cjs.map +1 -1
- package/build/legacy/useSuspenseQuery.d.cts +67 -0
- package/build/legacy/useSuspenseQuery.d.cts.map +1 -1
- package/build/legacy/useSuspenseQuery.d.ts +67 -0
- package/build/legacy/useSuspenseQuery.d.ts.map +1 -1
- package/build/legacy/useSuspenseQuery.js +67 -0
- package/build/legacy/useSuspenseQuery.js.map +1 -1
- package/build/modern/HydrationBoundary.cjs +44 -1
- 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 +44 -1
- 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 +76 -0
- package/build/modern/QueryErrorResetBoundary.cjs.map +1 -1
- package/build/modern/QueryErrorResetBoundary.d.cts +77 -0
- package/build/modern/QueryErrorResetBoundary.d.cts.map +1 -1
- package/build/modern/QueryErrorResetBoundary.d.ts +77 -0
- package/build/modern/QueryErrorResetBoundary.d.ts.map +1 -1
- package/build/modern/QueryErrorResetBoundary.js +76 -0
- package/build/modern/QueryErrorResetBoundary.js.map +1 -1
- package/build/modern/infiniteQueryOptions.cjs.map +1 -1
- package/build/modern/infiniteQueryOptions.d.cts +173 -0
- package/build/modern/infiniteQueryOptions.d.cts.map +1 -1
- package/build/modern/infiniteQueryOptions.d.ts +173 -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 +55 -0
- package/build/modern/mutationOptions.d.cts.map +1 -1
- package/build/modern/mutationOptions.d.ts +55 -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 +175 -0
- package/build/modern/queryOptions.d.cts.map +1 -1
- package/build/modern/queryOptions.d.ts +175 -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 +292 -0
- package/build/modern/useInfiniteQuery.d.cts.map +1 -1
- package/build/modern/useInfiniteQuery.d.ts +292 -0
- package/build/modern/useInfiniteQuery.d.ts.map +1 -1
- package/build/modern/useInfiniteQuery.js.map +1 -1
- package/build/modern/useIsFetching.cjs +36 -0
- package/build/modern/useIsFetching.cjs.map +1 -1
- package/build/modern/useIsFetching.d.cts +36 -0
- package/build/modern/useIsFetching.d.cts.map +1 -1
- package/build/modern/useIsFetching.d.ts +36 -0
- package/build/modern/useIsFetching.d.ts.map +1 -1
- package/build/modern/useIsFetching.js +36 -0
- package/build/modern/useIsFetching.js.map +1 -1
- package/build/modern/useMutation.cjs +172 -0
- package/build/modern/useMutation.cjs.map +1 -1
- package/build/modern/useMutation.d.cts +172 -0
- package/build/modern/useMutation.d.cts.map +1 -1
- package/build/modern/useMutation.d.ts +172 -0
- package/build/modern/useMutation.d.ts.map +1 -1
- package/build/modern/useMutation.js +172 -0
- package/build/modern/useMutation.js.map +1 -1
- package/build/modern/useMutationState.cjs +94 -0
- package/build/modern/useMutationState.cjs.map +1 -1
- package/build/modern/useMutationState.d.cts +94 -0
- package/build/modern/useMutationState.d.cts.map +1 -1
- package/build/modern/useMutationState.d.ts +94 -0
- package/build/modern/useMutationState.d.ts.map +1 -1
- package/build/modern/useMutationState.js +94 -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 +130 -0
- package/build/modern/useQueries.cjs.map +1 -1
- package/build/modern/useQueries.d.cts +165 -2
- package/build/modern/useQueries.d.cts.map +1 -1
- package/build/modern/useQueries.d.ts +165 -2
- package/build/modern/useQueries.d.ts.map +1 -1
- package/build/modern/useQueries.js +130 -0
- package/build/modern/useQueries.js.map +1 -1
- package/build/modern/useQuery.cjs.map +1 -1
- package/build/modern/useQuery.d.cts +246 -0
- package/build/modern/useQuery.d.cts.map +1 -1
- package/build/modern/useQuery.d.ts +246 -0
- package/build/modern/useQuery.d.ts.map +1 -1
- package/build/modern/useQuery.js.map +1 -1
- package/build/modern/useSuspenseInfiniteQuery.cjs +86 -0
- package/build/modern/useSuspenseInfiniteQuery.cjs.map +1 -1
- package/build/modern/useSuspenseInfiniteQuery.d.cts +86 -0
- package/build/modern/useSuspenseInfiniteQuery.d.cts.map +1 -1
- package/build/modern/useSuspenseInfiniteQuery.d.ts +86 -0
- package/build/modern/useSuspenseInfiniteQuery.d.ts.map +1 -1
- package/build/modern/useSuspenseInfiniteQuery.js +86 -0
- package/build/modern/useSuspenseInfiniteQuery.js.map +1 -1
- package/build/modern/useSuspenseQueries.cjs.map +1 -1
- package/build/modern/useSuspenseQueries.d.cts +320 -2
- package/build/modern/useSuspenseQueries.d.cts.map +1 -1
- package/build/modern/useSuspenseQueries.d.ts +320 -2
- package/build/modern/useSuspenseQueries.d.ts.map +1 -1
- package/build/modern/useSuspenseQueries.js.map +1 -1
- package/build/modern/useSuspenseQuery.cjs +67 -0
- package/build/modern/useSuspenseQuery.cjs.map +1 -1
- package/build/modern/useSuspenseQuery.d.cts +67 -0
- package/build/modern/useSuspenseQuery.d.cts.map +1 -1
- package/build/modern/useSuspenseQuery.d.ts +67 -0
- package/build/modern/useSuspenseQuery.d.ts.map +1 -1
- package/build/modern/useSuspenseQuery.js +67 -0
- package/build/modern/useSuspenseQuery.js.map +1 -1
- package/build/query-codemods/eslint.config.js +7 -0
- package/build/query-codemods/root.eslint.config.js +45 -0
- package/package.json +11 -11
- package/src/HydrationBoundary.tsx +61 -1
- package/src/IsRestoringProvider.ts +12 -0
- package/src/QueryClientProvider.tsx +41 -0
- package/src/QueryErrorResetBoundary.tsx +89 -0
- package/src/infiniteQueryOptions.ts +173 -0
- package/src/mutationOptions.ts +55 -0
- package/src/queryOptions.ts +175 -0
- package/src/types.ts +228 -2
- package/src/useInfiniteQuery.ts +292 -0
- package/src/useIsFetching.ts +36 -0
- package/src/useMutation.ts +172 -0
- package/src/useMutationState.ts +94 -0
- package/src/usePrefetchInfiniteQuery.tsx +44 -0
- package/src/usePrefetchQuery.tsx +35 -0
- package/src/useQueries.ts +165 -2
- package/src/useQuery.ts +246 -0
- package/src/useSuspenseInfiniteQuery.ts +86 -0
- package/src/useSuspenseQueries.ts +320 -2
- package/src/useSuspenseQuery.ts +67 -0
|
@@ -40,19 +40,337 @@ type GetUseSuspenseQueryResult<T> = T extends {
|
|
|
40
40
|
throwOnError?: ThrowOnError<any, infer TError, any, any>;
|
|
41
41
|
} ? UseSuspenseQueryResult<TQueryFnData, unknown extends TError ? DefaultError : TError> : UseSuspenseQueryResult;
|
|
42
42
|
/**
|
|
43
|
-
*
|
|
43
|
+
* The `queries` array accepted by `useSuspenseQueries`. Recursively unwraps each tuple element so every
|
|
44
|
+
* entry's `queryFn`/`select` are inferred individually, up to 20 elements. An opaque array (e.g. `unknown[]`)
|
|
45
|
+
* is returned as-is; a non-tuple array of a known element type, or a tuple past 20 elements, falls back to a
|
|
46
|
+
* single homogeneous {@link UseSuspenseQueryOptions} type.
|
|
47
|
+
*
|
|
48
|
+
* @template T - The type of the `queries` array as written at the call site.
|
|
49
|
+
* @template TResults - The internal accumulator that this type builds during recursion. It is not meant
|
|
50
|
+
* to be set explicitly.
|
|
51
|
+
* @template TDepth - The internal recursion-depth counter, checked against the 20-element limit. It is not
|
|
52
|
+
* meant to be set explicitly.
|
|
44
53
|
*/
|
|
45
54
|
type SuspenseQueriesOptions<T extends Array<any>, TResults extends Array<any> = [], TDepth extends ReadonlyArray<number> = []> = TDepth['length'] extends MAXIMUM_DEPTH ? Array<UseSuspenseQueryOptions> : T extends [] ? [] : T extends [infer Head] ? [...TResults, GetUseSuspenseQueryOptions<Head>] : T extends [infer Head, ...infer Tails] ? SuspenseQueriesOptions<[...Tails], [...TResults, GetUseSuspenseQueryOptions<Head>], [...TDepth, 1]> : Array<unknown> extends T ? T : T extends Array<UseSuspenseQueryOptions<infer TQueryFnData, infer TError, infer TData, infer TQueryKey>> ? Array<UseSuspenseQueryOptions<TQueryFnData, TError, TData, TQueryKey>> : Array<UseSuspenseQueryOptions>;
|
|
46
55
|
/**
|
|
47
|
-
*
|
|
56
|
+
* The result type returned by `useSuspenseQueries`, when no `combine` is provided. Mirrors
|
|
57
|
+
* {@link SuspenseQueriesOptions}: each tuple element's result type is inferred individually, up to 20 elements.
|
|
58
|
+
* A non-tuple array is mapped per-element instead, still inferring each entry individually; only past 20
|
|
59
|
+
* elements does this fall back to a single homogeneous {@link UseSuspenseQueryResult} type.
|
|
60
|
+
*
|
|
61
|
+
* @template T - The type of the `queries` array, as inferred by {@link SuspenseQueriesOptions}.
|
|
62
|
+
* @template TResults - The internal accumulator that this type builds during recursion. It is not meant
|
|
63
|
+
* to be set explicitly.
|
|
64
|
+
* @template TDepth - The internal recursion-depth counter, checked against the 20-element limit. It is not
|
|
65
|
+
* meant to be set explicitly.
|
|
48
66
|
*/
|
|
49
67
|
type SuspenseQueriesResults<T extends Array<any>, TResults extends Array<any> = [], TDepth extends ReadonlyArray<number> = []> = TDepth['length'] extends MAXIMUM_DEPTH ? Array<UseSuspenseQueryResult> : T extends [] ? [] : T extends [infer Head] ? [...TResults, GetUseSuspenseQueryResult<Head>] : T extends [infer Head, ...infer Tails] ? SuspenseQueriesResults<[...Tails], [...TResults, GetUseSuspenseQueryResult<Head>], [...TDepth, 1]> : { [K in keyof T]: GetUseSuspenseQueryResult<T[K]>; };
|
|
68
|
+
/**
|
|
69
|
+
* The options for `useSuspenseQueries` are the same as for `useQueries`, except that the top-level `subscribed`
|
|
70
|
+
* option isn't supported, and each `query` can't have `throwOnError`, `enabled`, or `placeholderData`.
|
|
71
|
+
*
|
|
72
|
+
* @param options - The `queries` array to run in Suspense, and an optional `combine` function.
|
|
73
|
+
* @param queryClient - Use this to provide a custom `QueryClient`. Otherwise, the one from the nearest context
|
|
74
|
+
* will be used.
|
|
75
|
+
* @returns The same structure as `useQueries`, except that for each `query`, `data` is guaranteed to be
|
|
76
|
+
* defined, `isPlaceholderData` is missing, and `status` is either `success` or `error` (with the derived
|
|
77
|
+
* flags set accordingly).
|
|
78
|
+
*
|
|
79
|
+
* Caveat: the component will only re-mount after all queries have finished loading. Hence, if a query has gone
|
|
80
|
+
* stale in the time it took for all the queries to complete, it will be fetched again at re-mount. To avoid
|
|
81
|
+
* this, make sure to set a high enough `staleTime`. Cancellation does not work.
|
|
82
|
+
*
|
|
83
|
+
* @example
|
|
84
|
+
* The query error is thrown if a fetch fails and no cached data exists yet, so an error boundary is
|
|
85
|
+
* required around `<Suspense>`. A failed background refetch instead continues to render the cached data.
|
|
86
|
+
* Use {@link QueryErrorResetBoundary} to let the user retry after such an error:
|
|
87
|
+
* ```tsx
|
|
88
|
+
* import { Suspense } from 'react'
|
|
89
|
+
* import { ErrorBoundary } from 'react-error-boundary'
|
|
90
|
+
* import {
|
|
91
|
+
* QueryErrorResetBoundary,
|
|
92
|
+
* useSuspenseQueries,
|
|
93
|
+
* } from '@tanstack/react-query'
|
|
94
|
+
*
|
|
95
|
+
* function Posts({ ids }: { ids: Array<number> }) {
|
|
96
|
+
* // Every result is guaranteed to be defined — no per-query `isPending` check needed.
|
|
97
|
+
* const postQueries = useSuspenseQueries({
|
|
98
|
+
* queries: ids.map((id) => ({
|
|
99
|
+
* queryKey: ['post', id],
|
|
100
|
+
* queryFn: () => fetchPost(id),
|
|
101
|
+
* })),
|
|
102
|
+
* })
|
|
103
|
+
*
|
|
104
|
+
* return (
|
|
105
|
+
* <ul>
|
|
106
|
+
* {postQueries.map((query) => (
|
|
107
|
+
* <li key={query.data.id}>{query.data.title}</li>
|
|
108
|
+
* ))}
|
|
109
|
+
* </ul>
|
|
110
|
+
* )
|
|
111
|
+
* }
|
|
112
|
+
*
|
|
113
|
+
* function App() {
|
|
114
|
+
* return (
|
|
115
|
+
* <QueryErrorResetBoundary>
|
|
116
|
+
* {({ reset }) => (
|
|
117
|
+
* <ErrorBoundary
|
|
118
|
+
* onReset={reset}
|
|
119
|
+
* fallbackRender={({ resetErrorBoundary }) => (
|
|
120
|
+
* <div>
|
|
121
|
+
* There was an error!
|
|
122
|
+
* <button onClick={() => resetErrorBoundary()}>Try again</button>
|
|
123
|
+
* </div>
|
|
124
|
+
* )}
|
|
125
|
+
* >
|
|
126
|
+
* <Suspense fallback={<h1>Loading posts...</h1>}>
|
|
127
|
+
* <Posts ids={[1, 2, 3]} />
|
|
128
|
+
* </Suspense>
|
|
129
|
+
* </ErrorBoundary>
|
|
130
|
+
* )}
|
|
131
|
+
* </QueryErrorResetBoundary>
|
|
132
|
+
* )
|
|
133
|
+
* }
|
|
134
|
+
* ```
|
|
135
|
+
*
|
|
136
|
+
* @example
|
|
137
|
+
* Several different queries — use `useSuspenseQueries` instead of multiple `useSuspenseQuery` calls, so
|
|
138
|
+
* they fetch in parallel rather than suspending one after another:
|
|
139
|
+
* ```tsx
|
|
140
|
+
* import { Suspense } from 'react'
|
|
141
|
+
* import { ErrorBoundary } from 'react-error-boundary'
|
|
142
|
+
* import {
|
|
143
|
+
* QueryErrorResetBoundary,
|
|
144
|
+
* useSuspenseQueries,
|
|
145
|
+
* } from '@tanstack/react-query'
|
|
146
|
+
*
|
|
147
|
+
* function Dashboard() {
|
|
148
|
+
* const [usersQuery, teamsQuery, projectsQuery] = useSuspenseQueries({
|
|
149
|
+
* queries: [
|
|
150
|
+
* { queryKey: ['users'], queryFn: fetchUsers },
|
|
151
|
+
* { queryKey: ['teams'], queryFn: fetchTeams },
|
|
152
|
+
* { queryKey: ['projects'], queryFn: fetchProjects },
|
|
153
|
+
* ],
|
|
154
|
+
* })
|
|
155
|
+
*
|
|
156
|
+
* return (
|
|
157
|
+
* <div>
|
|
158
|
+
* <UserList users={usersQuery.data} />
|
|
159
|
+
* <TeamList teams={teamsQuery.data} />
|
|
160
|
+
* <ProjectList projects={projectsQuery.data} />
|
|
161
|
+
* </div>
|
|
162
|
+
* )
|
|
163
|
+
* }
|
|
164
|
+
*
|
|
165
|
+
* function App() {
|
|
166
|
+
* return (
|
|
167
|
+
* <QueryErrorResetBoundary>
|
|
168
|
+
* {({ reset }) => (
|
|
169
|
+
* <ErrorBoundary
|
|
170
|
+
* onReset={reset}
|
|
171
|
+
* fallbackRender={({ resetErrorBoundary }) => (
|
|
172
|
+
* <div>
|
|
173
|
+
* There was an error!
|
|
174
|
+
* <button onClick={() => resetErrorBoundary()}>Try again</button>
|
|
175
|
+
* </div>
|
|
176
|
+
* )}
|
|
177
|
+
* >
|
|
178
|
+
* <Suspense fallback={<h1>Loading dashboard...</h1>}>
|
|
179
|
+
* <Dashboard />
|
|
180
|
+
* </Suspense>
|
|
181
|
+
* </ErrorBoundary>
|
|
182
|
+
* )}
|
|
183
|
+
* </QueryErrorResetBoundary>
|
|
184
|
+
* )
|
|
185
|
+
* }
|
|
186
|
+
* ```
|
|
187
|
+
*
|
|
188
|
+
* @example
|
|
189
|
+
* `combine`s the results into a single boolean, so `Refresh` only re-renders when that boolean changes,
|
|
190
|
+
* not on every individual query update. This overload is the only one that accepts `combine`:
|
|
191
|
+
* ```tsx
|
|
192
|
+
* import { Suspense } from 'react'
|
|
193
|
+
* import { ErrorBoundary } from 'react-error-boundary'
|
|
194
|
+
* import {
|
|
195
|
+
* QueryErrorResetBoundary,
|
|
196
|
+
* useSuspenseQueries,
|
|
197
|
+
* } from '@tanstack/react-query'
|
|
198
|
+
*
|
|
199
|
+
* function Refresh() {
|
|
200
|
+
* const anyFetching = useSuspenseQueries({
|
|
201
|
+
* queries: [
|
|
202
|
+
* { queryKey: ['users'], queryFn: fetchUsers },
|
|
203
|
+
* { queryKey: ['teams'], queryFn: fetchTeams },
|
|
204
|
+
* ],
|
|
205
|
+
* combine: (results) => results.some((result) => result.isFetching),
|
|
206
|
+
* })
|
|
207
|
+
*
|
|
208
|
+
* return anyFetching ? <span>Refreshing…</span> : null
|
|
209
|
+
* }
|
|
210
|
+
*
|
|
211
|
+
* function App() {
|
|
212
|
+
* return (
|
|
213
|
+
* <QueryErrorResetBoundary>
|
|
214
|
+
* {({ reset }) => (
|
|
215
|
+
* <ErrorBoundary
|
|
216
|
+
* onReset={reset}
|
|
217
|
+
* fallbackRender={({ resetErrorBoundary }) => (
|
|
218
|
+
* <div>
|
|
219
|
+
* There was an error!
|
|
220
|
+
* <button onClick={() => resetErrorBoundary()}>Try again</button>
|
|
221
|
+
* </div>
|
|
222
|
+
* )}
|
|
223
|
+
* >
|
|
224
|
+
* <Suspense fallback={<h1>Loading dashboard...</h1>}>
|
|
225
|
+
* <Refresh />
|
|
226
|
+
* </Suspense>
|
|
227
|
+
* </ErrorBoundary>
|
|
228
|
+
* )}
|
|
229
|
+
* </QueryErrorResetBoundary>
|
|
230
|
+
* )
|
|
231
|
+
* }
|
|
232
|
+
* ```
|
|
233
|
+
*/
|
|
50
234
|
declare function useSuspenseQueries<T extends Array<any>, TCombinedResult = SuspenseQueriesResults<T>>(options: {
|
|
235
|
+
/**
|
|
236
|
+
* An array with query option objects identical to `useSuspenseQuery`.
|
|
237
|
+
*/
|
|
51
238
|
queries: readonly [...SuspenseQueriesOptions<T>] | readonly [...{ [K in keyof T]: GetUseSuspenseQueryOptions<T[K]>; }];
|
|
239
|
+
/**
|
|
240
|
+
* Use this to combine the results of the queries into a single value. The result will be structurally
|
|
241
|
+
* shared to be as referentially stable as possible.
|
|
242
|
+
*/
|
|
52
243
|
combine?: (result: SuspenseQueriesResults<T>) => TCombinedResult;
|
|
53
244
|
}, queryClient?: QueryClient): TCombinedResult;
|
|
245
|
+
/**
|
|
246
|
+
* The options for `useSuspenseQueries` are the same as for `useQueries`, except that the top-level `subscribed`
|
|
247
|
+
* option isn't supported, and each `query` can't have `throwOnError`, `enabled`, or `placeholderData`.
|
|
248
|
+
*
|
|
249
|
+
* @param options - The `queries` array to run in Suspense, and an optional `combine` function.
|
|
250
|
+
* @param queryClient - Use this to provide a custom `QueryClient`. Otherwise, the one from the nearest context
|
|
251
|
+
* will be used.
|
|
252
|
+
* @returns The same structure as `useQueries`, except that for each `query`, `data` is guaranteed to be
|
|
253
|
+
* defined, `isPlaceholderData` is missing, and `status` is either `success` or `error` (with the derived
|
|
254
|
+
* flags set accordingly).
|
|
255
|
+
*
|
|
256
|
+
* Caveat: the component will only re-mount after all queries have finished loading. Hence, if a query has gone
|
|
257
|
+
* stale in the time it took for all the queries to complete, it will be fetched again at re-mount. To avoid
|
|
258
|
+
* this, make sure to set a high enough `staleTime`. Cancellation does not work.
|
|
259
|
+
*
|
|
260
|
+
* @example
|
|
261
|
+
* The query error is thrown if a fetch fails and no cached data exists yet, so an error boundary is
|
|
262
|
+
* required around `<Suspense>`. A failed background refetch instead continues to render the cached data.
|
|
263
|
+
* Use {@link QueryErrorResetBoundary} to let the user retry after such an error:
|
|
264
|
+
* ```tsx
|
|
265
|
+
* import { Suspense } from 'react'
|
|
266
|
+
* import { ErrorBoundary } from 'react-error-boundary'
|
|
267
|
+
* import {
|
|
268
|
+
* QueryErrorResetBoundary,
|
|
269
|
+
* useSuspenseQueries,
|
|
270
|
+
* } from '@tanstack/react-query'
|
|
271
|
+
*
|
|
272
|
+
* function Posts({ ids }: { ids: Array<number> }) {
|
|
273
|
+
* // Every result is guaranteed to be defined — no per-query `isPending` check needed.
|
|
274
|
+
* const postQueries = useSuspenseQueries({
|
|
275
|
+
* queries: ids.map((id) => ({
|
|
276
|
+
* queryKey: ['post', id],
|
|
277
|
+
* queryFn: () => fetchPost(id),
|
|
278
|
+
* })),
|
|
279
|
+
* })
|
|
280
|
+
*
|
|
281
|
+
* return (
|
|
282
|
+
* <ul>
|
|
283
|
+
* {postQueries.map((query) => (
|
|
284
|
+
* <li key={query.data.id}>{query.data.title}</li>
|
|
285
|
+
* ))}
|
|
286
|
+
* </ul>
|
|
287
|
+
* )
|
|
288
|
+
* }
|
|
289
|
+
*
|
|
290
|
+
* function App() {
|
|
291
|
+
* return (
|
|
292
|
+
* <QueryErrorResetBoundary>
|
|
293
|
+
* {({ reset }) => (
|
|
294
|
+
* <ErrorBoundary
|
|
295
|
+
* onReset={reset}
|
|
296
|
+
* fallbackRender={({ resetErrorBoundary }) => (
|
|
297
|
+
* <div>
|
|
298
|
+
* There was an error!
|
|
299
|
+
* <button onClick={() => resetErrorBoundary()}>Try again</button>
|
|
300
|
+
* </div>
|
|
301
|
+
* )}
|
|
302
|
+
* >
|
|
303
|
+
* <Suspense fallback={<h1>Loading posts...</h1>}>
|
|
304
|
+
* <Posts ids={[1, 2, 3]} />
|
|
305
|
+
* </Suspense>
|
|
306
|
+
* </ErrorBoundary>
|
|
307
|
+
* )}
|
|
308
|
+
* </QueryErrorResetBoundary>
|
|
309
|
+
* )
|
|
310
|
+
* }
|
|
311
|
+
* ```
|
|
312
|
+
*
|
|
313
|
+
* @example
|
|
314
|
+
* Several different queries — use `useSuspenseQueries` instead of multiple `useSuspenseQuery` calls, so
|
|
315
|
+
* they fetch in parallel rather than suspending one after another:
|
|
316
|
+
* ```tsx
|
|
317
|
+
* import { Suspense } from 'react'
|
|
318
|
+
* import { ErrorBoundary } from 'react-error-boundary'
|
|
319
|
+
* import {
|
|
320
|
+
* QueryErrorResetBoundary,
|
|
321
|
+
* useSuspenseQueries,
|
|
322
|
+
* } from '@tanstack/react-query'
|
|
323
|
+
*
|
|
324
|
+
* function Dashboard() {
|
|
325
|
+
* const [usersQuery, teamsQuery, projectsQuery] = useSuspenseQueries({
|
|
326
|
+
* queries: [
|
|
327
|
+
* { queryKey: ['users'], queryFn: fetchUsers },
|
|
328
|
+
* { queryKey: ['teams'], queryFn: fetchTeams },
|
|
329
|
+
* { queryKey: ['projects'], queryFn: fetchProjects },
|
|
330
|
+
* ],
|
|
331
|
+
* })
|
|
332
|
+
*
|
|
333
|
+
* return (
|
|
334
|
+
* <div>
|
|
335
|
+
* <UserList users={usersQuery.data} />
|
|
336
|
+
* <TeamList teams={teamsQuery.data} />
|
|
337
|
+
* <ProjectList projects={projectsQuery.data} />
|
|
338
|
+
* </div>
|
|
339
|
+
* )
|
|
340
|
+
* }
|
|
341
|
+
*
|
|
342
|
+
* function App() {
|
|
343
|
+
* return (
|
|
344
|
+
* <QueryErrorResetBoundary>
|
|
345
|
+
* {({ reset }) => (
|
|
346
|
+
* <ErrorBoundary
|
|
347
|
+
* onReset={reset}
|
|
348
|
+
* fallbackRender={({ resetErrorBoundary }) => (
|
|
349
|
+
* <div>
|
|
350
|
+
* There was an error!
|
|
351
|
+
* <button onClick={() => resetErrorBoundary()}>Try again</button>
|
|
352
|
+
* </div>
|
|
353
|
+
* )}
|
|
354
|
+
* >
|
|
355
|
+
* <Suspense fallback={<h1>Loading dashboard...</h1>}>
|
|
356
|
+
* <Dashboard />
|
|
357
|
+
* </Suspense>
|
|
358
|
+
* </ErrorBoundary>
|
|
359
|
+
* )}
|
|
360
|
+
* </QueryErrorResetBoundary>
|
|
361
|
+
* )
|
|
362
|
+
* }
|
|
363
|
+
* ```
|
|
364
|
+
*/
|
|
54
365
|
declare function useSuspenseQueries<T extends Array<any>, TCombinedResult = SuspenseQueriesResults<T>>(options: {
|
|
366
|
+
/**
|
|
367
|
+
* An array with query option objects identical to `useSuspenseQuery`.
|
|
368
|
+
*/
|
|
55
369
|
queries: readonly [...SuspenseQueriesOptions<T>];
|
|
370
|
+
/**
|
|
371
|
+
* Use this to combine the results of the queries into a single value. The result will be structurally
|
|
372
|
+
* shared to be as referentially stable as possible.
|
|
373
|
+
*/
|
|
56
374
|
combine?: (result: SuspenseQueriesResults<T>) => TCombinedResult;
|
|
57
375
|
}, queryClient?: QueryClient): TCombinedResult;
|
|
58
376
|
//#endregion
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useSuspenseQueries.d.cts","names":[],"sources":["../../src/useSuspenseQueries.ts"],"mappings":";;;KAaK;KAGA;KAEA,2BAA2B,KAE9B;EACE,mBAAmB;EACnB,cAAc;EACd,YAAY;IAEV,wBAAwB,cAAc,QAAQ,SAC9C;EAAY,mBAAmB;EAAc,cAAc;IACzD,wBAAwB,cAAc,UACtC;EAAY,YAAY;EAAO,cAAc;IAC3C,iCAAiC,QAAQ,SAEzC,iBAAiB,oBAAoB,cAAc,SACjD,wBAAwB,cAAc,QAAQ,SAC9C,iBAAiB,oBAAoB,UACnC,wBAAwB,cAAc,UACtC,iBAAiB,gBACf,wBAAwB,gBAExB;EACI,UACI,oBAAoB,oBAAoB,aACxC;EACJ,UAAU,oBAAoB;EAC9B,eAAe,wBAAwB;IAEzC,wBACE,cACA,QACA,OACA,aAEF;EACI,UACI,oBAAoB,oBAAoB,aACxC;EACJ,eAAe,wBAAwB;IAEzC,wBACE,cACA,QACA,cACA,aAGF;KAEf,0BAA0B,KAE7B;EAAY;EAAkB,cAAc;EAAQ,YAAY;IAC5D,uBAAuB,OAAO,UAC9B;EAAY,mBAAmB;EAAc,cAAc;IACzD,uBAAuB,cAAc,UACrC;EAAY,YAAY;EAAO,cAAc;IAC3C,uBAAuB,OAAO,UAE9B,sBAAsB,cAAc,SAClC,uBAAuB,OAAO,UAC9B,iBAAiB,oBAAoB,UACnC,uBAAuB,cAAc,UACrC,iBAAiB,gBACf,uBAAuB,gBAEvB;EACI,UACI,oBAAoB,qBACpB;EACJ,UAAU,oBAAoB;EAC9B,eAAe,wBAAwB;IAEzC,uCACkB,QAAQ,eAAe,uBACvB,SAAS,eAAe,UAE1C;EACI,UACI,oBAAoB,qBACpB;EACJ,eAAe,wBAAwB;IAEzC,uBACE,8BACgB,SAAS,eAAe,UAG1C
|
|
1
|
+
{"version":3,"file":"useSuspenseQueries.d.cts","names":[],"sources":["../../src/useSuspenseQueries.ts"],"mappings":";;;KAaK;KAGA;KAEA,2BAA2B,KAE9B;EACE,mBAAmB;EACnB,cAAc;EACd,YAAY;IAEV,wBAAwB,cAAc,QAAQ,SAC9C;EAAY,mBAAmB;EAAc,cAAc;IACzD,wBAAwB,cAAc,UACtC;EAAY,YAAY;EAAO,cAAc;IAC3C,iCAAiC,QAAQ,SAEzC,iBAAiB,oBAAoB,cAAc,SACjD,wBAAwB,cAAc,QAAQ,SAC9C,iBAAiB,oBAAoB,UACnC,wBAAwB,cAAc,UACtC,iBAAiB,gBACf,wBAAwB,gBAExB;EACI,UACI,oBAAoB,oBAAoB,aACxC;EACJ,UAAU,oBAAoB;EAC9B,eAAe,wBAAwB;IAEzC,wBACE,cACA,QACA,OACA,aAEF;EACI,UACI,oBAAoB,oBAAoB,aACxC;EACJ,eAAe,wBAAwB;IAEzC,wBACE,cACA,QACA,cACA,aAGF;KAEf,0BAA0B,KAE7B;EAAY;EAAkB,cAAc;EAAQ,YAAY;IAC5D,uBAAuB,OAAO,UAC9B;EAAY,mBAAmB;EAAc,cAAc;IACzD,uBAAuB,cAAc,UACrC;EAAY,YAAY;EAAO,cAAc;IAC3C,uBAAuB,OAAO,UAE9B,sBAAsB,cAAc,SAClC,uBAAuB,OAAO,UAC9B,iBAAiB,oBAAoB,UACnC,uBAAuB,cAAc,UACrC,iBAAiB,gBACf,uBAAuB,gBAEvB;EACI,UACI,oBAAoB,qBACpB;EACJ,UAAU,oBAAoB;EAC9B,eAAe,wBAAwB;IAEzC,uCACkB,QAAQ,eAAe,uBACvB,SAAS,eAAe,UAE1C;EACI,UACI,oBAAoB,qBACpB;EACJ,eAAe,wBAAwB;IAEzC,uBACE,8BACgB,SAAS,eAAe,UAG1C;;;;;;;;;;;;;KAcR,uBACV,UAAU,YACV,iBAAiB,iBACjB,eAAe,8BACb,yBAAyB,gBACzB,MAAM,2BACN,oBAEE,iBAAiB,YACX,UAAU,2BAA2B,SACzC,iBAAiB,eAAe,SAC9B,2BACM,YACA,UAAU,2BAA2B,YACrC,cAEN,uBAAuB,IACrB,IAGA,UAAU,MACN,8BACQ,oBACA,cACA,aACA,cAGV,MACE,wBAAwB,cAAc,QAAQ,OAAO,cAGvD,MAAM;;;;;;;;;;;;;KAcR,uBACV,UAAU,YACV,iBAAiB,iBACjB,eAAe,8BACb,yBAAyB,gBACzB,MAAM,0BACN,oBAEE,iBAAiB,YACX,UAAU,0BAA0B,SACxC,iBAAiB,eAAe,SAC9B,2BACM,YACA,UAAU,0BAA0B,YACpC,iBAEH,WAAW,IAAI,0BAA0B,EAAE;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;iBAwKxC,mBACd,UAAU,YACV,kBAAkB,uBAAuB,IAEzC;;;;EAIE,sBACiB,uBAAuB,sBACpB,WAAW,IAAI,2BAA2B,EAAE;;;;;EAKhE,WAAW,QAAQ,uBAAuB,OAAO;GAEnD,cAAc,cACb;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;iBA0Ha,mBACd,UAAU,YACV,kBAAkB,uBAAuB,IAEzC;;;;EAIE,sBAAsB,uBAAuB;;;;;EAK7C,WAAW,QAAQ,uBAAuB,OAAO;GAEnD,cAAc,cACb"}
|
|
@@ -40,19 +40,337 @@ type GetUseSuspenseQueryResult<T> = T extends {
|
|
|
40
40
|
throwOnError?: ThrowOnError<any, infer TError, any, any>;
|
|
41
41
|
} ? UseSuspenseQueryResult<TQueryFnData, unknown extends TError ? DefaultError : TError> : UseSuspenseQueryResult;
|
|
42
42
|
/**
|
|
43
|
-
*
|
|
43
|
+
* The `queries` array accepted by `useSuspenseQueries`. Recursively unwraps each tuple element so every
|
|
44
|
+
* entry's `queryFn`/`select` are inferred individually, up to 20 elements. An opaque array (e.g. `unknown[]`)
|
|
45
|
+
* is returned as-is; a non-tuple array of a known element type, or a tuple past 20 elements, falls back to a
|
|
46
|
+
* single homogeneous {@link UseSuspenseQueryOptions} type.
|
|
47
|
+
*
|
|
48
|
+
* @template T - The type of the `queries` array as written at the call site.
|
|
49
|
+
* @template TResults - The internal accumulator that this type builds during recursion. It is not meant
|
|
50
|
+
* to be set explicitly.
|
|
51
|
+
* @template TDepth - The internal recursion-depth counter, checked against the 20-element limit. It is not
|
|
52
|
+
* meant to be set explicitly.
|
|
44
53
|
*/
|
|
45
54
|
type SuspenseQueriesOptions<T extends Array<any>, TResults extends Array<any> = [], TDepth extends ReadonlyArray<number> = []> = TDepth['length'] extends MAXIMUM_DEPTH ? Array<UseSuspenseQueryOptions> : T extends [] ? [] : T extends [infer Head] ? [...TResults, GetUseSuspenseQueryOptions<Head>] : T extends [infer Head, ...infer Tails] ? SuspenseQueriesOptions<[...Tails], [...TResults, GetUseSuspenseQueryOptions<Head>], [...TDepth, 1]> : Array<unknown> extends T ? T : T extends Array<UseSuspenseQueryOptions<infer TQueryFnData, infer TError, infer TData, infer TQueryKey>> ? Array<UseSuspenseQueryOptions<TQueryFnData, TError, TData, TQueryKey>> : Array<UseSuspenseQueryOptions>;
|
|
46
55
|
/**
|
|
47
|
-
*
|
|
56
|
+
* The result type returned by `useSuspenseQueries`, when no `combine` is provided. Mirrors
|
|
57
|
+
* {@link SuspenseQueriesOptions}: each tuple element's result type is inferred individually, up to 20 elements.
|
|
58
|
+
* A non-tuple array is mapped per-element instead, still inferring each entry individually; only past 20
|
|
59
|
+
* elements does this fall back to a single homogeneous {@link UseSuspenseQueryResult} type.
|
|
60
|
+
*
|
|
61
|
+
* @template T - The type of the `queries` array, as inferred by {@link SuspenseQueriesOptions}.
|
|
62
|
+
* @template TResults - The internal accumulator that this type builds during recursion. It is not meant
|
|
63
|
+
* to be set explicitly.
|
|
64
|
+
* @template TDepth - The internal recursion-depth counter, checked against the 20-element limit. It is not
|
|
65
|
+
* meant to be set explicitly.
|
|
48
66
|
*/
|
|
49
67
|
type SuspenseQueriesResults<T extends Array<any>, TResults extends Array<any> = [], TDepth extends ReadonlyArray<number> = []> = TDepth['length'] extends MAXIMUM_DEPTH ? Array<UseSuspenseQueryResult> : T extends [] ? [] : T extends [infer Head] ? [...TResults, GetUseSuspenseQueryResult<Head>] : T extends [infer Head, ...infer Tails] ? SuspenseQueriesResults<[...Tails], [...TResults, GetUseSuspenseQueryResult<Head>], [...TDepth, 1]> : { [K in keyof T]: GetUseSuspenseQueryResult<T[K]>; };
|
|
68
|
+
/**
|
|
69
|
+
* The options for `useSuspenseQueries` are the same as for `useQueries`, except that the top-level `subscribed`
|
|
70
|
+
* option isn't supported, and each `query` can't have `throwOnError`, `enabled`, or `placeholderData`.
|
|
71
|
+
*
|
|
72
|
+
* @param options - The `queries` array to run in Suspense, and an optional `combine` function.
|
|
73
|
+
* @param queryClient - Use this to provide a custom `QueryClient`. Otherwise, the one from the nearest context
|
|
74
|
+
* will be used.
|
|
75
|
+
* @returns The same structure as `useQueries`, except that for each `query`, `data` is guaranteed to be
|
|
76
|
+
* defined, `isPlaceholderData` is missing, and `status` is either `success` or `error` (with the derived
|
|
77
|
+
* flags set accordingly).
|
|
78
|
+
*
|
|
79
|
+
* Caveat: the component will only re-mount after all queries have finished loading. Hence, if a query has gone
|
|
80
|
+
* stale in the time it took for all the queries to complete, it will be fetched again at re-mount. To avoid
|
|
81
|
+
* this, make sure to set a high enough `staleTime`. Cancellation does not work.
|
|
82
|
+
*
|
|
83
|
+
* @example
|
|
84
|
+
* The query error is thrown if a fetch fails and no cached data exists yet, so an error boundary is
|
|
85
|
+
* required around `<Suspense>`. A failed background refetch instead continues to render the cached data.
|
|
86
|
+
* Use {@link QueryErrorResetBoundary} to let the user retry after such an error:
|
|
87
|
+
* ```tsx
|
|
88
|
+
* import { Suspense } from 'react'
|
|
89
|
+
* import { ErrorBoundary } from 'react-error-boundary'
|
|
90
|
+
* import {
|
|
91
|
+
* QueryErrorResetBoundary,
|
|
92
|
+
* useSuspenseQueries,
|
|
93
|
+
* } from '@tanstack/react-query'
|
|
94
|
+
*
|
|
95
|
+
* function Posts({ ids }: { ids: Array<number> }) {
|
|
96
|
+
* // Every result is guaranteed to be defined — no per-query `isPending` check needed.
|
|
97
|
+
* const postQueries = useSuspenseQueries({
|
|
98
|
+
* queries: ids.map((id) => ({
|
|
99
|
+
* queryKey: ['post', id],
|
|
100
|
+
* queryFn: () => fetchPost(id),
|
|
101
|
+
* })),
|
|
102
|
+
* })
|
|
103
|
+
*
|
|
104
|
+
* return (
|
|
105
|
+
* <ul>
|
|
106
|
+
* {postQueries.map((query) => (
|
|
107
|
+
* <li key={query.data.id}>{query.data.title}</li>
|
|
108
|
+
* ))}
|
|
109
|
+
* </ul>
|
|
110
|
+
* )
|
|
111
|
+
* }
|
|
112
|
+
*
|
|
113
|
+
* function App() {
|
|
114
|
+
* return (
|
|
115
|
+
* <QueryErrorResetBoundary>
|
|
116
|
+
* {({ reset }) => (
|
|
117
|
+
* <ErrorBoundary
|
|
118
|
+
* onReset={reset}
|
|
119
|
+
* fallbackRender={({ resetErrorBoundary }) => (
|
|
120
|
+
* <div>
|
|
121
|
+
* There was an error!
|
|
122
|
+
* <button onClick={() => resetErrorBoundary()}>Try again</button>
|
|
123
|
+
* </div>
|
|
124
|
+
* )}
|
|
125
|
+
* >
|
|
126
|
+
* <Suspense fallback={<h1>Loading posts...</h1>}>
|
|
127
|
+
* <Posts ids={[1, 2, 3]} />
|
|
128
|
+
* </Suspense>
|
|
129
|
+
* </ErrorBoundary>
|
|
130
|
+
* )}
|
|
131
|
+
* </QueryErrorResetBoundary>
|
|
132
|
+
* )
|
|
133
|
+
* }
|
|
134
|
+
* ```
|
|
135
|
+
*
|
|
136
|
+
* @example
|
|
137
|
+
* Several different queries — use `useSuspenseQueries` instead of multiple `useSuspenseQuery` calls, so
|
|
138
|
+
* they fetch in parallel rather than suspending one after another:
|
|
139
|
+
* ```tsx
|
|
140
|
+
* import { Suspense } from 'react'
|
|
141
|
+
* import { ErrorBoundary } from 'react-error-boundary'
|
|
142
|
+
* import {
|
|
143
|
+
* QueryErrorResetBoundary,
|
|
144
|
+
* useSuspenseQueries,
|
|
145
|
+
* } from '@tanstack/react-query'
|
|
146
|
+
*
|
|
147
|
+
* function Dashboard() {
|
|
148
|
+
* const [usersQuery, teamsQuery, projectsQuery] = useSuspenseQueries({
|
|
149
|
+
* queries: [
|
|
150
|
+
* { queryKey: ['users'], queryFn: fetchUsers },
|
|
151
|
+
* { queryKey: ['teams'], queryFn: fetchTeams },
|
|
152
|
+
* { queryKey: ['projects'], queryFn: fetchProjects },
|
|
153
|
+
* ],
|
|
154
|
+
* })
|
|
155
|
+
*
|
|
156
|
+
* return (
|
|
157
|
+
* <div>
|
|
158
|
+
* <UserList users={usersQuery.data} />
|
|
159
|
+
* <TeamList teams={teamsQuery.data} />
|
|
160
|
+
* <ProjectList projects={projectsQuery.data} />
|
|
161
|
+
* </div>
|
|
162
|
+
* )
|
|
163
|
+
* }
|
|
164
|
+
*
|
|
165
|
+
* function App() {
|
|
166
|
+
* return (
|
|
167
|
+
* <QueryErrorResetBoundary>
|
|
168
|
+
* {({ reset }) => (
|
|
169
|
+
* <ErrorBoundary
|
|
170
|
+
* onReset={reset}
|
|
171
|
+
* fallbackRender={({ resetErrorBoundary }) => (
|
|
172
|
+
* <div>
|
|
173
|
+
* There was an error!
|
|
174
|
+
* <button onClick={() => resetErrorBoundary()}>Try again</button>
|
|
175
|
+
* </div>
|
|
176
|
+
* )}
|
|
177
|
+
* >
|
|
178
|
+
* <Suspense fallback={<h1>Loading dashboard...</h1>}>
|
|
179
|
+
* <Dashboard />
|
|
180
|
+
* </Suspense>
|
|
181
|
+
* </ErrorBoundary>
|
|
182
|
+
* )}
|
|
183
|
+
* </QueryErrorResetBoundary>
|
|
184
|
+
* )
|
|
185
|
+
* }
|
|
186
|
+
* ```
|
|
187
|
+
*
|
|
188
|
+
* @example
|
|
189
|
+
* `combine`s the results into a single boolean, so `Refresh` only re-renders when that boolean changes,
|
|
190
|
+
* not on every individual query update. This overload is the only one that accepts `combine`:
|
|
191
|
+
* ```tsx
|
|
192
|
+
* import { Suspense } from 'react'
|
|
193
|
+
* import { ErrorBoundary } from 'react-error-boundary'
|
|
194
|
+
* import {
|
|
195
|
+
* QueryErrorResetBoundary,
|
|
196
|
+
* useSuspenseQueries,
|
|
197
|
+
* } from '@tanstack/react-query'
|
|
198
|
+
*
|
|
199
|
+
* function Refresh() {
|
|
200
|
+
* const anyFetching = useSuspenseQueries({
|
|
201
|
+
* queries: [
|
|
202
|
+
* { queryKey: ['users'], queryFn: fetchUsers },
|
|
203
|
+
* { queryKey: ['teams'], queryFn: fetchTeams },
|
|
204
|
+
* ],
|
|
205
|
+
* combine: (results) => results.some((result) => result.isFetching),
|
|
206
|
+
* })
|
|
207
|
+
*
|
|
208
|
+
* return anyFetching ? <span>Refreshing…</span> : null
|
|
209
|
+
* }
|
|
210
|
+
*
|
|
211
|
+
* function App() {
|
|
212
|
+
* return (
|
|
213
|
+
* <QueryErrorResetBoundary>
|
|
214
|
+
* {({ reset }) => (
|
|
215
|
+
* <ErrorBoundary
|
|
216
|
+
* onReset={reset}
|
|
217
|
+
* fallbackRender={({ resetErrorBoundary }) => (
|
|
218
|
+
* <div>
|
|
219
|
+
* There was an error!
|
|
220
|
+
* <button onClick={() => resetErrorBoundary()}>Try again</button>
|
|
221
|
+
* </div>
|
|
222
|
+
* )}
|
|
223
|
+
* >
|
|
224
|
+
* <Suspense fallback={<h1>Loading dashboard...</h1>}>
|
|
225
|
+
* <Refresh />
|
|
226
|
+
* </Suspense>
|
|
227
|
+
* </ErrorBoundary>
|
|
228
|
+
* )}
|
|
229
|
+
* </QueryErrorResetBoundary>
|
|
230
|
+
* )
|
|
231
|
+
* }
|
|
232
|
+
* ```
|
|
233
|
+
*/
|
|
50
234
|
declare function useSuspenseQueries<T extends Array<any>, TCombinedResult = SuspenseQueriesResults<T>>(options: {
|
|
235
|
+
/**
|
|
236
|
+
* An array with query option objects identical to `useSuspenseQuery`.
|
|
237
|
+
*/
|
|
51
238
|
queries: readonly [...SuspenseQueriesOptions<T>] | readonly [...{ [K in keyof T]: GetUseSuspenseQueryOptions<T[K]>; }];
|
|
239
|
+
/**
|
|
240
|
+
* Use this to combine the results of the queries into a single value. The result will be structurally
|
|
241
|
+
* shared to be as referentially stable as possible.
|
|
242
|
+
*/
|
|
52
243
|
combine?: (result: SuspenseQueriesResults<T>) => TCombinedResult;
|
|
53
244
|
}, queryClient?: QueryClient): TCombinedResult;
|
|
245
|
+
/**
|
|
246
|
+
* The options for `useSuspenseQueries` are the same as for `useQueries`, except that the top-level `subscribed`
|
|
247
|
+
* option isn't supported, and each `query` can't have `throwOnError`, `enabled`, or `placeholderData`.
|
|
248
|
+
*
|
|
249
|
+
* @param options - The `queries` array to run in Suspense, and an optional `combine` function.
|
|
250
|
+
* @param queryClient - Use this to provide a custom `QueryClient`. Otherwise, the one from the nearest context
|
|
251
|
+
* will be used.
|
|
252
|
+
* @returns The same structure as `useQueries`, except that for each `query`, `data` is guaranteed to be
|
|
253
|
+
* defined, `isPlaceholderData` is missing, and `status` is either `success` or `error` (with the derived
|
|
254
|
+
* flags set accordingly).
|
|
255
|
+
*
|
|
256
|
+
* Caveat: the component will only re-mount after all queries have finished loading. Hence, if a query has gone
|
|
257
|
+
* stale in the time it took for all the queries to complete, it will be fetched again at re-mount. To avoid
|
|
258
|
+
* this, make sure to set a high enough `staleTime`. Cancellation does not work.
|
|
259
|
+
*
|
|
260
|
+
* @example
|
|
261
|
+
* The query error is thrown if a fetch fails and no cached data exists yet, so an error boundary is
|
|
262
|
+
* required around `<Suspense>`. A failed background refetch instead continues to render the cached data.
|
|
263
|
+
* Use {@link QueryErrorResetBoundary} to let the user retry after such an error:
|
|
264
|
+
* ```tsx
|
|
265
|
+
* import { Suspense } from 'react'
|
|
266
|
+
* import { ErrorBoundary } from 'react-error-boundary'
|
|
267
|
+
* import {
|
|
268
|
+
* QueryErrorResetBoundary,
|
|
269
|
+
* useSuspenseQueries,
|
|
270
|
+
* } from '@tanstack/react-query'
|
|
271
|
+
*
|
|
272
|
+
* function Posts({ ids }: { ids: Array<number> }) {
|
|
273
|
+
* // Every result is guaranteed to be defined — no per-query `isPending` check needed.
|
|
274
|
+
* const postQueries = useSuspenseQueries({
|
|
275
|
+
* queries: ids.map((id) => ({
|
|
276
|
+
* queryKey: ['post', id],
|
|
277
|
+
* queryFn: () => fetchPost(id),
|
|
278
|
+
* })),
|
|
279
|
+
* })
|
|
280
|
+
*
|
|
281
|
+
* return (
|
|
282
|
+
* <ul>
|
|
283
|
+
* {postQueries.map((query) => (
|
|
284
|
+
* <li key={query.data.id}>{query.data.title}</li>
|
|
285
|
+
* ))}
|
|
286
|
+
* </ul>
|
|
287
|
+
* )
|
|
288
|
+
* }
|
|
289
|
+
*
|
|
290
|
+
* function App() {
|
|
291
|
+
* return (
|
|
292
|
+
* <QueryErrorResetBoundary>
|
|
293
|
+
* {({ reset }) => (
|
|
294
|
+
* <ErrorBoundary
|
|
295
|
+
* onReset={reset}
|
|
296
|
+
* fallbackRender={({ resetErrorBoundary }) => (
|
|
297
|
+
* <div>
|
|
298
|
+
* There was an error!
|
|
299
|
+
* <button onClick={() => resetErrorBoundary()}>Try again</button>
|
|
300
|
+
* </div>
|
|
301
|
+
* )}
|
|
302
|
+
* >
|
|
303
|
+
* <Suspense fallback={<h1>Loading posts...</h1>}>
|
|
304
|
+
* <Posts ids={[1, 2, 3]} />
|
|
305
|
+
* </Suspense>
|
|
306
|
+
* </ErrorBoundary>
|
|
307
|
+
* )}
|
|
308
|
+
* </QueryErrorResetBoundary>
|
|
309
|
+
* )
|
|
310
|
+
* }
|
|
311
|
+
* ```
|
|
312
|
+
*
|
|
313
|
+
* @example
|
|
314
|
+
* Several different queries — use `useSuspenseQueries` instead of multiple `useSuspenseQuery` calls, so
|
|
315
|
+
* they fetch in parallel rather than suspending one after another:
|
|
316
|
+
* ```tsx
|
|
317
|
+
* import { Suspense } from 'react'
|
|
318
|
+
* import { ErrorBoundary } from 'react-error-boundary'
|
|
319
|
+
* import {
|
|
320
|
+
* QueryErrorResetBoundary,
|
|
321
|
+
* useSuspenseQueries,
|
|
322
|
+
* } from '@tanstack/react-query'
|
|
323
|
+
*
|
|
324
|
+
* function Dashboard() {
|
|
325
|
+
* const [usersQuery, teamsQuery, projectsQuery] = useSuspenseQueries({
|
|
326
|
+
* queries: [
|
|
327
|
+
* { queryKey: ['users'], queryFn: fetchUsers },
|
|
328
|
+
* { queryKey: ['teams'], queryFn: fetchTeams },
|
|
329
|
+
* { queryKey: ['projects'], queryFn: fetchProjects },
|
|
330
|
+
* ],
|
|
331
|
+
* })
|
|
332
|
+
*
|
|
333
|
+
* return (
|
|
334
|
+
* <div>
|
|
335
|
+
* <UserList users={usersQuery.data} />
|
|
336
|
+
* <TeamList teams={teamsQuery.data} />
|
|
337
|
+
* <ProjectList projects={projectsQuery.data} />
|
|
338
|
+
* </div>
|
|
339
|
+
* )
|
|
340
|
+
* }
|
|
341
|
+
*
|
|
342
|
+
* function App() {
|
|
343
|
+
* return (
|
|
344
|
+
* <QueryErrorResetBoundary>
|
|
345
|
+
* {({ reset }) => (
|
|
346
|
+
* <ErrorBoundary
|
|
347
|
+
* onReset={reset}
|
|
348
|
+
* fallbackRender={({ resetErrorBoundary }) => (
|
|
349
|
+
* <div>
|
|
350
|
+
* There was an error!
|
|
351
|
+
* <button onClick={() => resetErrorBoundary()}>Try again</button>
|
|
352
|
+
* </div>
|
|
353
|
+
* )}
|
|
354
|
+
* >
|
|
355
|
+
* <Suspense fallback={<h1>Loading dashboard...</h1>}>
|
|
356
|
+
* <Dashboard />
|
|
357
|
+
* </Suspense>
|
|
358
|
+
* </ErrorBoundary>
|
|
359
|
+
* )}
|
|
360
|
+
* </QueryErrorResetBoundary>
|
|
361
|
+
* )
|
|
362
|
+
* }
|
|
363
|
+
* ```
|
|
364
|
+
*/
|
|
54
365
|
declare function useSuspenseQueries<T extends Array<any>, TCombinedResult = SuspenseQueriesResults<T>>(options: {
|
|
366
|
+
/**
|
|
367
|
+
* An array with query option objects identical to `useSuspenseQuery`.
|
|
368
|
+
*/
|
|
55
369
|
queries: readonly [...SuspenseQueriesOptions<T>];
|
|
370
|
+
/**
|
|
371
|
+
* Use this to combine the results of the queries into a single value. The result will be structurally
|
|
372
|
+
* shared to be as referentially stable as possible.
|
|
373
|
+
*/
|
|
56
374
|
combine?: (result: SuspenseQueriesResults<T>) => TCombinedResult;
|
|
57
375
|
}, queryClient?: QueryClient): TCombinedResult;
|
|
58
376
|
//#endregion
|