@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
|
@@ -15,6 +15,62 @@ import type {
|
|
|
15
15
|
} from './types'
|
|
16
16
|
import { useBaseQuery } from './useBaseQuery'
|
|
17
17
|
|
|
18
|
+
/**
|
|
19
|
+
* The options for `useSuspenseInfiniteQuery` are the same as for `useInfiniteQuery`, except for `throwOnError`,
|
|
20
|
+
* `enabled`, and `placeholderData`.
|
|
21
|
+
*
|
|
22
|
+
* Caveat: cancellation does not work.
|
|
23
|
+
*
|
|
24
|
+
* @param options - The {@link UseSuspenseInfiniteQueryOptions} to use — the same options as `useInfiniteQuery`, minus the ones listed above.
|
|
25
|
+
* @param queryClient - Use this to use a custom `QueryClient`. Otherwise, the one from the nearest context will
|
|
26
|
+
* be used.
|
|
27
|
+
* @returns The same object as `useInfiniteQuery`, except that `data` is guaranteed to be defined,
|
|
28
|
+
* `isPlaceholderData` is missing, and `status` is either `success` or `error` (with the derived flags set
|
|
29
|
+
* accordingly).
|
|
30
|
+
*
|
|
31
|
+
* @example
|
|
32
|
+
* ```tsx
|
|
33
|
+
* import { Suspense } from 'preact/compat'
|
|
34
|
+
* import { useSuspenseInfiniteQuery } from '@tanstack/preact-query'
|
|
35
|
+
*
|
|
36
|
+
* function Projects() {
|
|
37
|
+
* // `data` is guaranteed to be defined here — no `isPending` check needed.
|
|
38
|
+
* const { data, fetchNextPage, hasNextPage, isFetching, isFetchingNextPage } =
|
|
39
|
+
* useSuspenseInfiniteQuery({
|
|
40
|
+
* queryKey: ['projects'],
|
|
41
|
+
* queryFn: ({ pageParam }) => fetchProjects(pageParam),
|
|
42
|
+
* initialPageParam: 0,
|
|
43
|
+
* getNextPageParam: (lastPage) => lastPage.nextId,
|
|
44
|
+
* })
|
|
45
|
+
*
|
|
46
|
+
* return (
|
|
47
|
+
* <div>
|
|
48
|
+
* {data.pages.map((page) =>
|
|
49
|
+
* page.projects.map((project) => <p key={project.id}>{project.name}</p>),
|
|
50
|
+
* )}
|
|
51
|
+
* <button
|
|
52
|
+
* onClick={() => fetchNextPage()}
|
|
53
|
+
* disabled={!hasNextPage || isFetching}
|
|
54
|
+
* >
|
|
55
|
+
* {isFetchingNextPage
|
|
56
|
+
* ? 'Loading more...'
|
|
57
|
+
* : hasNextPage
|
|
58
|
+
* ? 'Load More'
|
|
59
|
+
* : 'Nothing more to load'}
|
|
60
|
+
* </button>
|
|
61
|
+
* </div>
|
|
62
|
+
* )
|
|
63
|
+
* }
|
|
64
|
+
*
|
|
65
|
+
* function App() {
|
|
66
|
+
* return (
|
|
67
|
+
* <Suspense fallback={<h1>Loading projects...</h1>}>
|
|
68
|
+
* <Projects />
|
|
69
|
+
* </Suspense>
|
|
70
|
+
* )
|
|
71
|
+
* }
|
|
72
|
+
* ```
|
|
73
|
+
*/
|
|
18
74
|
export function useSuspenseInfiniteQuery<
|
|
19
75
|
TQueryFnData,
|
|
20
76
|
TError = DefaultError,
|
|
@@ -105,7 +105,16 @@ type GetUseSuspenseQueryResult<T> =
|
|
|
105
105
|
UseSuspenseQueryResult
|
|
106
106
|
|
|
107
107
|
/**
|
|
108
|
-
*
|
|
108
|
+
* The `queries` array accepted by `useSuspenseQueries`. Recursively unwraps each tuple element so every
|
|
109
|
+
* entry's `queryFn`/`select` are inferred individually, up to 20 elements. An opaque array (e.g. `unknown[]`)
|
|
110
|
+
* is returned as-is; a non-tuple array of a known element type, or a tuple past 20 elements, falls back to a
|
|
111
|
+
* single homogeneous {@link UseSuspenseQueryOptions} type.
|
|
112
|
+
*
|
|
113
|
+
* @template T - The type of the `queries` array as written at the call site.
|
|
114
|
+
* @template TResults - The internal accumulator that this type builds during recursion. It is not meant
|
|
115
|
+
* to be set explicitly.
|
|
116
|
+
* @template TDepth - The internal recursion-depth counter, checked against the 20-element limit. It is not
|
|
117
|
+
* meant to be set explicitly.
|
|
109
118
|
*/
|
|
110
119
|
export type SuspenseQueriesOptions<
|
|
111
120
|
T extends Array<any>,
|
|
@@ -142,7 +151,16 @@ export type SuspenseQueriesOptions<
|
|
|
142
151
|
Array<UseSuspenseQueryOptions>
|
|
143
152
|
|
|
144
153
|
/**
|
|
145
|
-
*
|
|
154
|
+
* The result type returned by `useSuspenseQueries`, when no `combine` is provided. Mirrors
|
|
155
|
+
* {@link SuspenseQueriesOptions}: each tuple element's result type is inferred individually, up to 20 elements.
|
|
156
|
+
* A non-tuple array is mapped per-element instead, still inferring each entry individually; only past 20
|
|
157
|
+
* elements does this fall back to a single homogeneous {@link UseSuspenseQueryResult} type.
|
|
158
|
+
*
|
|
159
|
+
* @template T - The type of the `queries` array, as inferred by {@link SuspenseQueriesOptions}.
|
|
160
|
+
* @template TResults - The internal accumulator that this type builds during recursion. It is not meant
|
|
161
|
+
* to be set explicitly.
|
|
162
|
+
* @template TDepth - The internal recursion-depth counter, checked against the 20-element limit. It is not
|
|
163
|
+
* meant to be set explicitly.
|
|
146
164
|
*/
|
|
147
165
|
export type SuspenseQueriesResults<
|
|
148
166
|
T extends Array<any>,
|
|
@@ -162,25 +180,201 @@ export type SuspenseQueriesResults<
|
|
|
162
180
|
>
|
|
163
181
|
: { [K in keyof T]: GetUseSuspenseQueryResult<T[K]> }
|
|
164
182
|
|
|
183
|
+
/**
|
|
184
|
+
* The options for `useSuspenseQueries` are the same as for `useQueries`, except that each `query` can't have
|
|
185
|
+
* `throwOnError`, `enabled`, or `placeholderData`.
|
|
186
|
+
*
|
|
187
|
+
* @param options - The `queries` array to run in Suspense, and an optional `combine` function.
|
|
188
|
+
* @param queryClient - Use this to provide a custom `QueryClient`. Otherwise, the one from the nearest context
|
|
189
|
+
* will be used.
|
|
190
|
+
* @returns The same structure as `useQueries`, except that for each `query`, `data` is guaranteed to be
|
|
191
|
+
* defined, `isPlaceholderData` is missing, and `status` is either `success` or `error` (with the derived
|
|
192
|
+
* flags set accordingly).
|
|
193
|
+
*
|
|
194
|
+
* Caveat: the component will only re-mount after all queries have finished loading. Hence, if a query has gone
|
|
195
|
+
* stale in the time it took for all the queries to complete, it will be fetched again at re-mount. To avoid
|
|
196
|
+
* this, make sure to set a high enough `staleTime`. Cancellation does not work.
|
|
197
|
+
*
|
|
198
|
+
* @example
|
|
199
|
+
* ```tsx
|
|
200
|
+
* import { Suspense } from 'preact/compat'
|
|
201
|
+
* import { useSuspenseQueries } from '@tanstack/preact-query'
|
|
202
|
+
*
|
|
203
|
+
* function Posts({ ids }: { ids: Array<number> }) {
|
|
204
|
+
* // Every result is guaranteed to be defined — no per-query `isPending` check needed.
|
|
205
|
+
* const postQueries = useSuspenseQueries({
|
|
206
|
+
* queries: ids.map((id) => ({
|
|
207
|
+
* queryKey: ['post', id],
|
|
208
|
+
* queryFn: () => fetchPost(id),
|
|
209
|
+
* })),
|
|
210
|
+
* })
|
|
211
|
+
*
|
|
212
|
+
* return (
|
|
213
|
+
* <ul>
|
|
214
|
+
* {postQueries.map((query) => (
|
|
215
|
+
* <li key={query.data.id}>{query.data.title}</li>
|
|
216
|
+
* ))}
|
|
217
|
+
* </ul>
|
|
218
|
+
* )
|
|
219
|
+
* }
|
|
220
|
+
*
|
|
221
|
+
* function App() {
|
|
222
|
+
* return (
|
|
223
|
+
* <Suspense fallback={<h1>Loading posts...</h1>}>
|
|
224
|
+
* <Posts ids={[1, 2, 3]} />
|
|
225
|
+
* </Suspense>
|
|
226
|
+
* )
|
|
227
|
+
* }
|
|
228
|
+
* ```
|
|
229
|
+
*
|
|
230
|
+
* @example
|
|
231
|
+
* Several different queries — use `useSuspenseQueries` instead of multiple `useSuspenseQuery` calls, so
|
|
232
|
+
* they fetch in parallel rather than suspending one after another:
|
|
233
|
+
* ```tsx
|
|
234
|
+
* import { Suspense } from 'preact/compat'
|
|
235
|
+
* import { useSuspenseQueries } from '@tanstack/preact-query'
|
|
236
|
+
*
|
|
237
|
+
* function Dashboard() {
|
|
238
|
+
* const [usersQuery, teamsQuery, projectsQuery] = useSuspenseQueries({
|
|
239
|
+
* queries: [
|
|
240
|
+
* { queryKey: ['users'], queryFn: fetchUsers },
|
|
241
|
+
* { queryKey: ['teams'], queryFn: fetchTeams },
|
|
242
|
+
* { queryKey: ['projects'], queryFn: fetchProjects },
|
|
243
|
+
* ],
|
|
244
|
+
* })
|
|
245
|
+
*
|
|
246
|
+
* return (
|
|
247
|
+
* <div>
|
|
248
|
+
* <UserList users={usersQuery.data} />
|
|
249
|
+
* <TeamList teams={teamsQuery.data} />
|
|
250
|
+
* <ProjectList projects={projectsQuery.data} />
|
|
251
|
+
* </div>
|
|
252
|
+
* )
|
|
253
|
+
* }
|
|
254
|
+
*
|
|
255
|
+
* function App() {
|
|
256
|
+
* return (
|
|
257
|
+
* <Suspense fallback={<h1>Loading dashboard...</h1>}>
|
|
258
|
+
* <Dashboard />
|
|
259
|
+
* </Suspense>
|
|
260
|
+
* )
|
|
261
|
+
* }
|
|
262
|
+
* ```
|
|
263
|
+
*/
|
|
165
264
|
export function useSuspenseQueries<
|
|
166
265
|
T extends Array<any>,
|
|
167
266
|
TCombinedResult = SuspenseQueriesResults<T>,
|
|
168
267
|
>(
|
|
169
268
|
options: {
|
|
269
|
+
/**
|
|
270
|
+
* An array with query option objects identical to `useSuspenseQuery`.
|
|
271
|
+
*/
|
|
170
272
|
queries:
|
|
171
273
|
| readonly [...SuspenseQueriesOptions<T>]
|
|
172
274
|
| readonly [...{ [K in keyof T]: GetUseSuspenseQueryOptions<T[K]> }]
|
|
275
|
+
/**
|
|
276
|
+
* Use this to combine the results of the queries into a single value. The result will be structurally
|
|
277
|
+
* shared to be as referentially stable as possible.
|
|
278
|
+
*/
|
|
173
279
|
combine?: (result: SuspenseQueriesResults<T>) => TCombinedResult
|
|
174
280
|
},
|
|
175
281
|
queryClient?: QueryClient,
|
|
176
282
|
): TCombinedResult
|
|
177
283
|
|
|
284
|
+
/**
|
|
285
|
+
* The options for `useSuspenseQueries` are the same as for `useQueries`, except that each `query` can't have
|
|
286
|
+
* `throwOnError`, `enabled`, or `placeholderData`.
|
|
287
|
+
*
|
|
288
|
+
* @param options - The `queries` array to run in Suspense, and an optional `combine` function.
|
|
289
|
+
* @param queryClient - Use this to provide a custom `QueryClient`. Otherwise, the one from the nearest context
|
|
290
|
+
* will be used.
|
|
291
|
+
* @returns The same structure as `useQueries`, except that for each `query`, `data` is guaranteed to be
|
|
292
|
+
* defined, `isPlaceholderData` is missing, and `status` is either `success` or `error` (with the derived
|
|
293
|
+
* flags set accordingly).
|
|
294
|
+
*
|
|
295
|
+
* Caveat: the component will only re-mount after all queries have finished loading. Hence, if a query has gone
|
|
296
|
+
* stale in the time it took for all the queries to complete, it will be fetched again at re-mount. To avoid
|
|
297
|
+
* this, make sure to set a high enough `staleTime`. Cancellation does not work.
|
|
298
|
+
*
|
|
299
|
+
* @example
|
|
300
|
+
* ```tsx
|
|
301
|
+
* import { Suspense } from 'preact/compat'
|
|
302
|
+
* import { useSuspenseQueries } from '@tanstack/preact-query'
|
|
303
|
+
*
|
|
304
|
+
* function Posts({ ids }: { ids: Array<number> }) {
|
|
305
|
+
* // Every result is guaranteed to be defined — no per-query `isPending` check needed.
|
|
306
|
+
* const postQueries = useSuspenseQueries({
|
|
307
|
+
* queries: ids.map((id) => ({
|
|
308
|
+
* queryKey: ['post', id],
|
|
309
|
+
* queryFn: () => fetchPost(id),
|
|
310
|
+
* })),
|
|
311
|
+
* })
|
|
312
|
+
*
|
|
313
|
+
* return (
|
|
314
|
+
* <ul>
|
|
315
|
+
* {postQueries.map((query) => (
|
|
316
|
+
* <li key={query.data.id}>{query.data.title}</li>
|
|
317
|
+
* ))}
|
|
318
|
+
* </ul>
|
|
319
|
+
* )
|
|
320
|
+
* }
|
|
321
|
+
*
|
|
322
|
+
* function App() {
|
|
323
|
+
* return (
|
|
324
|
+
* <Suspense fallback={<h1>Loading posts...</h1>}>
|
|
325
|
+
* <Posts ids={[1, 2, 3]} />
|
|
326
|
+
* </Suspense>
|
|
327
|
+
* )
|
|
328
|
+
* }
|
|
329
|
+
* ```
|
|
330
|
+
*
|
|
331
|
+
* @example
|
|
332
|
+
* Several different queries — use `useSuspenseQueries` instead of multiple `useSuspenseQuery` calls, so
|
|
333
|
+
* they fetch in parallel rather than suspending one after another:
|
|
334
|
+
* ```tsx
|
|
335
|
+
* import { Suspense } from 'preact/compat'
|
|
336
|
+
* import { useSuspenseQueries } from '@tanstack/preact-query'
|
|
337
|
+
*
|
|
338
|
+
* function Dashboard() {
|
|
339
|
+
* const [usersQuery, teamsQuery, projectsQuery] = useSuspenseQueries({
|
|
340
|
+
* queries: [
|
|
341
|
+
* { queryKey: ['users'], queryFn: fetchUsers },
|
|
342
|
+
* { queryKey: ['teams'], queryFn: fetchTeams },
|
|
343
|
+
* { queryKey: ['projects'], queryFn: fetchProjects },
|
|
344
|
+
* ],
|
|
345
|
+
* })
|
|
346
|
+
*
|
|
347
|
+
* return (
|
|
348
|
+
* <div>
|
|
349
|
+
* <UserList users={usersQuery.data} />
|
|
350
|
+
* <TeamList teams={teamsQuery.data} />
|
|
351
|
+
* <ProjectList projects={projectsQuery.data} />
|
|
352
|
+
* </div>
|
|
353
|
+
* )
|
|
354
|
+
* }
|
|
355
|
+
*
|
|
356
|
+
* function App() {
|
|
357
|
+
* return (
|
|
358
|
+
* <Suspense fallback={<h1>Loading dashboard...</h1>}>
|
|
359
|
+
* <Dashboard />
|
|
360
|
+
* </Suspense>
|
|
361
|
+
* )
|
|
362
|
+
* }
|
|
363
|
+
* ```
|
|
364
|
+
*/
|
|
178
365
|
export function useSuspenseQueries<
|
|
179
366
|
T extends Array<any>,
|
|
180
367
|
TCombinedResult = SuspenseQueriesResults<T>,
|
|
181
368
|
>(
|
|
182
369
|
options: {
|
|
370
|
+
/**
|
|
371
|
+
* An array with query option objects identical to `useSuspenseQuery`.
|
|
372
|
+
*/
|
|
183
373
|
queries: readonly [...SuspenseQueriesOptions<T>]
|
|
374
|
+
/**
|
|
375
|
+
* Use this to combine the results of the queries into a single value. The result will be structurally
|
|
376
|
+
* shared to be as referentially stable as possible.
|
|
377
|
+
*/
|
|
184
378
|
combine?: (result: SuspenseQueriesResults<T>) => TCombinedResult
|
|
185
379
|
},
|
|
186
380
|
queryClient?: QueryClient,
|
package/src/useSuspenseQuery.ts
CHANGED
|
@@ -5,6 +5,53 @@ import { defaultThrowOnError } from './suspense'
|
|
|
5
5
|
import type { UseSuspenseQueryOptions, UseSuspenseQueryResult } from './types'
|
|
6
6
|
import { useBaseQuery } from './useBaseQuery'
|
|
7
7
|
|
|
8
|
+
/**
|
|
9
|
+
* The options for `useSuspenseQuery` are the same as for `useQuery`, except for `throwOnError`, `enabled`, and
|
|
10
|
+
* `placeholderData`.
|
|
11
|
+
*
|
|
12
|
+
* Caveat: cancellation does not work.
|
|
13
|
+
*
|
|
14
|
+
* @remarks Multiple `useSuspenseQuery` calls in the same component suspend serially, causing a request
|
|
15
|
+
* waterfall — each one blocks rendering until it resolves, so the next doesn't even start fetching until then.
|
|
16
|
+
* Use {@link useSuspenseQueries} instead when you have more than one suspenseful query in a component, so they
|
|
17
|
+
* fetch in parallel.
|
|
18
|
+
* @param options - The {@link UseSuspenseQueryOptions} to use — the same options as `useQuery`, minus the ones listed above.
|
|
19
|
+
* @param queryClient - Use this to use a custom `QueryClient`. Otherwise, the one from the nearest context will
|
|
20
|
+
* be used.
|
|
21
|
+
* @returns The same object as `useQuery`, except that `data` is guaranteed to be defined, `isPlaceholderData`
|
|
22
|
+
* is missing, and `status` is either `success` or `error` (with the derived flags set accordingly).
|
|
23
|
+
*
|
|
24
|
+
* @example
|
|
25
|
+
* ```tsx
|
|
26
|
+
* import { Suspense } from 'preact/compat'
|
|
27
|
+
* import { useSuspenseQuery } from '@tanstack/preact-query'
|
|
28
|
+
*
|
|
29
|
+
* function Posts() {
|
|
30
|
+
* // `data` is guaranteed to be defined here — no `isPending` check needed.
|
|
31
|
+
* const { data, isFetching } = useSuspenseQuery({
|
|
32
|
+
* queryKey: ['posts'],
|
|
33
|
+
* queryFn: fetchPosts,
|
|
34
|
+
* })
|
|
35
|
+
*
|
|
36
|
+
* return (
|
|
37
|
+
* <div>
|
|
38
|
+
* <h1>Posts {isFetching ? <Spinner /> : null}</h1>
|
|
39
|
+
* {data.map((post) => (
|
|
40
|
+
* <p key={post.id}>{post.title}</p>
|
|
41
|
+
* ))}
|
|
42
|
+
* </div>
|
|
43
|
+
* )
|
|
44
|
+
* }
|
|
45
|
+
*
|
|
46
|
+
* function App() {
|
|
47
|
+
* return (
|
|
48
|
+
* <Suspense fallback={<h1>Loading posts...</h1>}>
|
|
49
|
+
* <Posts />
|
|
50
|
+
* </Suspense>
|
|
51
|
+
* )
|
|
52
|
+
* }
|
|
53
|
+
* ```
|
|
54
|
+
*/
|
|
8
55
|
export function useSuspenseQuery<
|
|
9
56
|
TQueryFnData = unknown,
|
|
10
57
|
TError = DefaultError,
|