@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
|
@@ -8,11 +8,88 @@ interface QueryErrorResetBoundaryValue {
|
|
|
8
8
|
isReset: QueryErrorIsResetFunction;
|
|
9
9
|
reset: QueryErrorResetFunction;
|
|
10
10
|
}
|
|
11
|
+
/**
|
|
12
|
+
* This hook will reset any query errors within the closest `QueryErrorResetBoundary`. If there is no boundary
|
|
13
|
+
* defined it will reset them globally.
|
|
14
|
+
*
|
|
15
|
+
* @returns The boundary's {@link QueryErrorResetBoundaryValue}.
|
|
16
|
+
*
|
|
17
|
+
* @example
|
|
18
|
+
* ```tsx
|
|
19
|
+
* import { ErrorBoundary } from 'react-error-boundary'
|
|
20
|
+
* import { useQueryErrorResetBoundary } from '@tanstack/react-query'
|
|
21
|
+
*
|
|
22
|
+
* function App({ children }: { children: React.ReactNode }) {
|
|
23
|
+
* const { reset } = useQueryErrorResetBoundary()
|
|
24
|
+
*
|
|
25
|
+
* return (
|
|
26
|
+
* <ErrorBoundary
|
|
27
|
+
* onReset={reset}
|
|
28
|
+
* fallbackRender={({ resetErrorBoundary }) => (
|
|
29
|
+
* <div>
|
|
30
|
+
* There was an error!
|
|
31
|
+
* <button onClick={() => resetErrorBoundary()}>Try again</button>
|
|
32
|
+
* </div>
|
|
33
|
+
* )}
|
|
34
|
+
* >
|
|
35
|
+
* {children}
|
|
36
|
+
* </ErrorBoundary>
|
|
37
|
+
* )
|
|
38
|
+
* }
|
|
39
|
+
* ```
|
|
40
|
+
*/
|
|
11
41
|
declare const useQueryErrorResetBoundary: () => QueryErrorResetBoundaryValue;
|
|
42
|
+
/**
|
|
43
|
+
* A render-prop function usable as `children` on `QueryErrorResetBoundary`.
|
|
44
|
+
*
|
|
45
|
+
* @param value - The boundary's {@link QueryErrorResetBoundaryValue}.
|
|
46
|
+
* @returns The children to render.
|
|
47
|
+
*/
|
|
12
48
|
type QueryErrorResetBoundaryFunction = (value: QueryErrorResetBoundaryValue) => React.ReactNode;
|
|
49
|
+
/**
|
|
50
|
+
* The props accepted by `QueryErrorResetBoundary`.
|
|
51
|
+
*/
|
|
13
52
|
interface QueryErrorResetBoundaryProps {
|
|
53
|
+
/**
|
|
54
|
+
* Either a plain node, or a function that receives the boundary's {@link QueryErrorResetBoundaryValue} and
|
|
55
|
+
* returns a node.
|
|
56
|
+
*/
|
|
14
57
|
children: QueryErrorResetBoundaryFunction | React.ReactNode;
|
|
15
58
|
}
|
|
59
|
+
/**
|
|
60
|
+
* When using `suspense` or `throwOnError` in your queries, you need a way to let queries know that you want to
|
|
61
|
+
* try again when re-rendering after some error occurred. With the `QueryErrorResetBoundary` component you can
|
|
62
|
+
* reset any query errors within the boundaries of the component.
|
|
63
|
+
*
|
|
64
|
+
* @returns The `children`, rendered as-is, or called with the boundary's {@link QueryErrorResetBoundaryValue}
|
|
65
|
+
* if `children` is a function.
|
|
66
|
+
*
|
|
67
|
+
* @example
|
|
68
|
+
* ```tsx
|
|
69
|
+
* import { ErrorBoundary } from 'react-error-boundary'
|
|
70
|
+
* import { QueryErrorResetBoundary } from '@tanstack/react-query'
|
|
71
|
+
*
|
|
72
|
+
* function App() {
|
|
73
|
+
* return (
|
|
74
|
+
* <QueryErrorResetBoundary>
|
|
75
|
+
* {({ reset }) => (
|
|
76
|
+
* <ErrorBoundary
|
|
77
|
+
* onReset={reset}
|
|
78
|
+
* fallbackRender={({ resetErrorBoundary }) => (
|
|
79
|
+
* <div>
|
|
80
|
+
* There was an error!
|
|
81
|
+
* <button onClick={() => resetErrorBoundary()}>Try again</button>
|
|
82
|
+
* </div>
|
|
83
|
+
* )}
|
|
84
|
+
* >
|
|
85
|
+
* <Page />
|
|
86
|
+
* </ErrorBoundary>
|
|
87
|
+
* )}
|
|
88
|
+
* </QueryErrorResetBoundary>
|
|
89
|
+
* )
|
|
90
|
+
* }
|
|
91
|
+
* ```
|
|
92
|
+
*/
|
|
16
93
|
declare const QueryErrorResetBoundary: ({ children }: QueryErrorResetBoundaryProps) => import("react/jsx-runtime").JSX.Element;
|
|
17
94
|
//#endregion
|
|
18
95
|
export { QueryErrorClearResetFunction, QueryErrorIsResetFunction, QueryErrorResetBoundary, QueryErrorResetBoundaryFunction, QueryErrorResetBoundaryProps, QueryErrorResetBoundaryValue, QueryErrorResetFunction, useQueryErrorResetBoundary };
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"QueryErrorResetBoundary.d.cts","names":[],"sources":["../../src/QueryErrorResetBoundary.tsx"],"mappings":";;KAIY;KACA;KACA;UAEK;EACf,YAAY;EACZ,SAAS;EACT,OAAO
|
|
1
|
+
{"version":3,"file":"QueryErrorResetBoundary.d.cts","names":[],"sources":["../../src/QueryErrorResetBoundary.tsx"],"mappings":";;KAIY;KACA;KACA;UAEK;EACf,YAAY;EACZ,SAAS;EACT,OAAO;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;cAgEI,kCAA0B;;;;;;;KAW3B,mCACV,OAAO,iCACJ,MAAM;;;;UAKM;;;;;EAKf,UAAU,kCAAkC,MAAM;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;cAqCvC,4BAA2B,YAErC,6DAA4B,IAAA"}
|
|
@@ -8,11 +8,88 @@ interface QueryErrorResetBoundaryValue {
|
|
|
8
8
|
isReset: QueryErrorIsResetFunction;
|
|
9
9
|
reset: QueryErrorResetFunction;
|
|
10
10
|
}
|
|
11
|
+
/**
|
|
12
|
+
* This hook will reset any query errors within the closest `QueryErrorResetBoundary`. If there is no boundary
|
|
13
|
+
* defined it will reset them globally.
|
|
14
|
+
*
|
|
15
|
+
* @returns The boundary's {@link QueryErrorResetBoundaryValue}.
|
|
16
|
+
*
|
|
17
|
+
* @example
|
|
18
|
+
* ```tsx
|
|
19
|
+
* import { ErrorBoundary } from 'react-error-boundary'
|
|
20
|
+
* import { useQueryErrorResetBoundary } from '@tanstack/react-query'
|
|
21
|
+
*
|
|
22
|
+
* function App({ children }: { children: React.ReactNode }) {
|
|
23
|
+
* const { reset } = useQueryErrorResetBoundary()
|
|
24
|
+
*
|
|
25
|
+
* return (
|
|
26
|
+
* <ErrorBoundary
|
|
27
|
+
* onReset={reset}
|
|
28
|
+
* fallbackRender={({ resetErrorBoundary }) => (
|
|
29
|
+
* <div>
|
|
30
|
+
* There was an error!
|
|
31
|
+
* <button onClick={() => resetErrorBoundary()}>Try again</button>
|
|
32
|
+
* </div>
|
|
33
|
+
* )}
|
|
34
|
+
* >
|
|
35
|
+
* {children}
|
|
36
|
+
* </ErrorBoundary>
|
|
37
|
+
* )
|
|
38
|
+
* }
|
|
39
|
+
* ```
|
|
40
|
+
*/
|
|
11
41
|
declare const useQueryErrorResetBoundary: () => QueryErrorResetBoundaryValue;
|
|
42
|
+
/**
|
|
43
|
+
* A render-prop function usable as `children` on `QueryErrorResetBoundary`.
|
|
44
|
+
*
|
|
45
|
+
* @param value - The boundary's {@link QueryErrorResetBoundaryValue}.
|
|
46
|
+
* @returns The children to render.
|
|
47
|
+
*/
|
|
12
48
|
type QueryErrorResetBoundaryFunction = (value: QueryErrorResetBoundaryValue) => React.ReactNode;
|
|
49
|
+
/**
|
|
50
|
+
* The props accepted by `QueryErrorResetBoundary`.
|
|
51
|
+
*/
|
|
13
52
|
interface QueryErrorResetBoundaryProps {
|
|
53
|
+
/**
|
|
54
|
+
* Either a plain node, or a function that receives the boundary's {@link QueryErrorResetBoundaryValue} and
|
|
55
|
+
* returns a node.
|
|
56
|
+
*/
|
|
14
57
|
children: QueryErrorResetBoundaryFunction | React.ReactNode;
|
|
15
58
|
}
|
|
59
|
+
/**
|
|
60
|
+
* When using `suspense` or `throwOnError` in your queries, you need a way to let queries know that you want to
|
|
61
|
+
* try again when re-rendering after some error occurred. With the `QueryErrorResetBoundary` component you can
|
|
62
|
+
* reset any query errors within the boundaries of the component.
|
|
63
|
+
*
|
|
64
|
+
* @returns The `children`, rendered as-is, or called with the boundary's {@link QueryErrorResetBoundaryValue}
|
|
65
|
+
* if `children` is a function.
|
|
66
|
+
*
|
|
67
|
+
* @example
|
|
68
|
+
* ```tsx
|
|
69
|
+
* import { ErrorBoundary } from 'react-error-boundary'
|
|
70
|
+
* import { QueryErrorResetBoundary } from '@tanstack/react-query'
|
|
71
|
+
*
|
|
72
|
+
* function App() {
|
|
73
|
+
* return (
|
|
74
|
+
* <QueryErrorResetBoundary>
|
|
75
|
+
* {({ reset }) => (
|
|
76
|
+
* <ErrorBoundary
|
|
77
|
+
* onReset={reset}
|
|
78
|
+
* fallbackRender={({ resetErrorBoundary }) => (
|
|
79
|
+
* <div>
|
|
80
|
+
* There was an error!
|
|
81
|
+
* <button onClick={() => resetErrorBoundary()}>Try again</button>
|
|
82
|
+
* </div>
|
|
83
|
+
* )}
|
|
84
|
+
* >
|
|
85
|
+
* <Page />
|
|
86
|
+
* </ErrorBoundary>
|
|
87
|
+
* )}
|
|
88
|
+
* </QueryErrorResetBoundary>
|
|
89
|
+
* )
|
|
90
|
+
* }
|
|
91
|
+
* ```
|
|
92
|
+
*/
|
|
16
93
|
declare const QueryErrorResetBoundary: ({ children }: QueryErrorResetBoundaryProps) => import("react/jsx-runtime").JSX.Element;
|
|
17
94
|
//#endregion
|
|
18
95
|
export { QueryErrorClearResetFunction, QueryErrorIsResetFunction, QueryErrorResetBoundary, QueryErrorResetBoundaryFunction, QueryErrorResetBoundaryProps, QueryErrorResetBoundaryValue, QueryErrorResetFunction, useQueryErrorResetBoundary };
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"QueryErrorResetBoundary.d.ts","names":[],"sources":["../../src/QueryErrorResetBoundary.tsx"],"mappings":";;KAIY;KACA;KACA;UAEK;EACf,YAAY;EACZ,SAAS;EACT,OAAO
|
|
1
|
+
{"version":3,"file":"QueryErrorResetBoundary.d.ts","names":[],"sources":["../../src/QueryErrorResetBoundary.tsx"],"mappings":";;KAIY;KACA;KACA;UAEK;EACf,YAAY;EACZ,SAAS;EACT,OAAO;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;cAgEI,kCAA0B;;;;;;;KAW3B,mCACV,OAAO,iCACJ,MAAM;;;;UAKM;;;;;EAKf,UAAU,kCAAkC,MAAM;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;cAqCvC,4BAA2B,YAErC,6DAA4B,IAAA"}
|
|
@@ -2,22 +2,98 @@
|
|
|
2
2
|
import * as React from "react";
|
|
3
3
|
import { jsx } from "react/jsx-runtime";
|
|
4
4
|
//#region src/QueryErrorResetBoundary.tsx
|
|
5
|
+
/**
|
|
6
|
+
* Resets any query errors within the boundary, so queries know they can try again.
|
|
7
|
+
*/
|
|
5
8
|
function createValue() {
|
|
6
9
|
let isReset = false;
|
|
7
10
|
return {
|
|
11
|
+
/**
|
|
12
|
+
* Clears the reset state, so queries know not to try again until the boundary is reset again.
|
|
13
|
+
*/
|
|
8
14
|
clearReset: () => {
|
|
9
15
|
isReset = false;
|
|
10
16
|
},
|
|
17
|
+
/**
|
|
18
|
+
* Resets any query errors within the boundary, so queries know they can try again.
|
|
19
|
+
*/
|
|
11
20
|
reset: () => {
|
|
12
21
|
isReset = true;
|
|
13
22
|
},
|
|
23
|
+
/**
|
|
24
|
+
* Returns whether the boundary has been reset and not yet cleared.
|
|
25
|
+
*/
|
|
14
26
|
isReset: () => {
|
|
15
27
|
return isReset;
|
|
16
28
|
}
|
|
17
29
|
};
|
|
18
30
|
}
|
|
19
31
|
const QueryErrorResetBoundaryContext = React.createContext(createValue());
|
|
32
|
+
/**
|
|
33
|
+
* This hook will reset any query errors within the closest `QueryErrorResetBoundary`. If there is no boundary
|
|
34
|
+
* defined it will reset them globally.
|
|
35
|
+
*
|
|
36
|
+
* @returns The boundary's {@link QueryErrorResetBoundaryValue}.
|
|
37
|
+
*
|
|
38
|
+
* @example
|
|
39
|
+
* ```tsx
|
|
40
|
+
* import { ErrorBoundary } from 'react-error-boundary'
|
|
41
|
+
* import { useQueryErrorResetBoundary } from '@tanstack/react-query'
|
|
42
|
+
*
|
|
43
|
+
* function App({ children }: { children: React.ReactNode }) {
|
|
44
|
+
* const { reset } = useQueryErrorResetBoundary()
|
|
45
|
+
*
|
|
46
|
+
* return (
|
|
47
|
+
* <ErrorBoundary
|
|
48
|
+
* onReset={reset}
|
|
49
|
+
* fallbackRender={({ resetErrorBoundary }) => (
|
|
50
|
+
* <div>
|
|
51
|
+
* There was an error!
|
|
52
|
+
* <button onClick={() => resetErrorBoundary()}>Try again</button>
|
|
53
|
+
* </div>
|
|
54
|
+
* )}
|
|
55
|
+
* >
|
|
56
|
+
* {children}
|
|
57
|
+
* </ErrorBoundary>
|
|
58
|
+
* )
|
|
59
|
+
* }
|
|
60
|
+
* ```
|
|
61
|
+
*/
|
|
20
62
|
const useQueryErrorResetBoundary = () => React.useContext(QueryErrorResetBoundaryContext);
|
|
63
|
+
/**
|
|
64
|
+
* When using `suspense` or `throwOnError` in your queries, you need a way to let queries know that you want to
|
|
65
|
+
* try again when re-rendering after some error occurred. With the `QueryErrorResetBoundary` component you can
|
|
66
|
+
* reset any query errors within the boundaries of the component.
|
|
67
|
+
*
|
|
68
|
+
* @returns The `children`, rendered as-is, or called with the boundary's {@link QueryErrorResetBoundaryValue}
|
|
69
|
+
* if `children` is a function.
|
|
70
|
+
*
|
|
71
|
+
* @example
|
|
72
|
+
* ```tsx
|
|
73
|
+
* import { ErrorBoundary } from 'react-error-boundary'
|
|
74
|
+
* import { QueryErrorResetBoundary } from '@tanstack/react-query'
|
|
75
|
+
*
|
|
76
|
+
* function App() {
|
|
77
|
+
* return (
|
|
78
|
+
* <QueryErrorResetBoundary>
|
|
79
|
+
* {({ reset }) => (
|
|
80
|
+
* <ErrorBoundary
|
|
81
|
+
* onReset={reset}
|
|
82
|
+
* fallbackRender={({ resetErrorBoundary }) => (
|
|
83
|
+
* <div>
|
|
84
|
+
* There was an error!
|
|
85
|
+
* <button onClick={() => resetErrorBoundary()}>Try again</button>
|
|
86
|
+
* </div>
|
|
87
|
+
* )}
|
|
88
|
+
* >
|
|
89
|
+
* <Page />
|
|
90
|
+
* </ErrorBoundary>
|
|
91
|
+
* )}
|
|
92
|
+
* </QueryErrorResetBoundary>
|
|
93
|
+
* )
|
|
94
|
+
* }
|
|
95
|
+
* ```
|
|
96
|
+
*/
|
|
21
97
|
const QueryErrorResetBoundary = ({ children }) => {
|
|
22
98
|
const [value] = React.useState(() => createValue());
|
|
23
99
|
return /* @__PURE__ */ jsx(QueryErrorResetBoundaryContext.Provider, {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"QueryErrorResetBoundary.js","names":[],"sources":["../../src/QueryErrorResetBoundary.tsx"],"sourcesContent":["'use client'\nimport * as React from 'react'\n\n// CONTEXT\nexport type QueryErrorResetFunction = () => void\nexport type QueryErrorIsResetFunction = () => boolean\nexport type QueryErrorClearResetFunction = () => void\n\nexport interface QueryErrorResetBoundaryValue {\n clearReset: QueryErrorClearResetFunction\n isReset: QueryErrorIsResetFunction\n reset: QueryErrorResetFunction\n}\n\nfunction createValue(): QueryErrorResetBoundaryValue {\n let isReset = false\n return {\n clearReset: () => {\n isReset = false\n },\n reset: () => {\n isReset = true\n },\n isReset: () => {\n return isReset\n },\n }\n}\n\nconst QueryErrorResetBoundaryContext = React.createContext(createValue())\n\n// HOOK\n\nexport const useQueryErrorResetBoundary = () =>\n React.useContext(QueryErrorResetBoundaryContext)\n\n// COMPONENT\n\nexport type QueryErrorResetBoundaryFunction = (\n value: QueryErrorResetBoundaryValue,\n) => React.ReactNode\n\nexport interface QueryErrorResetBoundaryProps {\n children: QueryErrorResetBoundaryFunction | React.ReactNode\n}\n\nexport const QueryErrorResetBoundary = ({\n children,\n}: QueryErrorResetBoundaryProps) => {\n const [value] = React.useState(() => createValue())\n return (\n <QueryErrorResetBoundaryContext.Provider value={value}>\n {typeof children === 'function' ? children(value) : children}\n </QueryErrorResetBoundaryContext.Provider>\n )\n}\n"],"mappings":"
|
|
1
|
+
{"version":3,"file":"QueryErrorResetBoundary.js","names":[],"sources":["../../src/QueryErrorResetBoundary.tsx"],"sourcesContent":["'use client'\nimport * as React from 'react'\n\n// CONTEXT\nexport type QueryErrorResetFunction = () => void\nexport type QueryErrorIsResetFunction = () => boolean\nexport type QueryErrorClearResetFunction = () => void\n\nexport interface QueryErrorResetBoundaryValue {\n clearReset: QueryErrorClearResetFunction\n isReset: QueryErrorIsResetFunction\n reset: QueryErrorResetFunction\n}\n\n/**\n * Resets any query errors within the boundary, so queries know they can try again.\n */\nfunction createValue(): QueryErrorResetBoundaryValue {\n let isReset = false\n return {\n /**\n * Clears the reset state, so queries know not to try again until the boundary is reset again.\n */\n clearReset: () => {\n isReset = false\n },\n /**\n * Resets any query errors within the boundary, so queries know they can try again.\n */\n reset: () => {\n isReset = true\n },\n /**\n * Returns whether the boundary has been reset and not yet cleared.\n */\n isReset: () => {\n return isReset\n },\n }\n}\n\nconst QueryErrorResetBoundaryContext = React.createContext(createValue())\n\n// HOOK\n\n/**\n * This hook will reset any query errors within the closest `QueryErrorResetBoundary`. If there is no boundary\n * defined it will reset them globally.\n *\n * @returns The boundary's {@link QueryErrorResetBoundaryValue}.\n *\n * @example\n * ```tsx\n * import { ErrorBoundary } from 'react-error-boundary'\n * import { useQueryErrorResetBoundary } from '@tanstack/react-query'\n *\n * function App({ children }: { children: React.ReactNode }) {\n * const { reset } = useQueryErrorResetBoundary()\n *\n * return (\n * <ErrorBoundary\n * onReset={reset}\n * fallbackRender={({ resetErrorBoundary }) => (\n * <div>\n * There was an error!\n * <button onClick={() => resetErrorBoundary()}>Try again</button>\n * </div>\n * )}\n * >\n * {children}\n * </ErrorBoundary>\n * )\n * }\n * ```\n */\nexport const useQueryErrorResetBoundary = () =>\n React.useContext(QueryErrorResetBoundaryContext)\n\n// COMPONENT\n\n/**\n * A render-prop function usable as `children` on `QueryErrorResetBoundary`.\n *\n * @param value - The boundary's {@link QueryErrorResetBoundaryValue}.\n * @returns The children to render.\n */\nexport type QueryErrorResetBoundaryFunction = (\n value: QueryErrorResetBoundaryValue,\n) => React.ReactNode\n\n/**\n * The props accepted by `QueryErrorResetBoundary`.\n */\nexport interface QueryErrorResetBoundaryProps {\n /**\n * Either a plain node, or a function that receives the boundary's {@link QueryErrorResetBoundaryValue} and\n * returns a node.\n */\n children: QueryErrorResetBoundaryFunction | React.ReactNode\n}\n\n/**\n * When using `suspense` or `throwOnError` in your queries, you need a way to let queries know that you want to\n * try again when re-rendering after some error occurred. With the `QueryErrorResetBoundary` component you can\n * reset any query errors within the boundaries of the component.\n *\n * @returns The `children`, rendered as-is, or called with the boundary's {@link QueryErrorResetBoundaryValue}\n * if `children` is a function.\n *\n * @example\n * ```tsx\n * import { ErrorBoundary } from 'react-error-boundary'\n * import { QueryErrorResetBoundary } from '@tanstack/react-query'\n *\n * function App() {\n * return (\n * <QueryErrorResetBoundary>\n * {({ reset }) => (\n * <ErrorBoundary\n * onReset={reset}\n * fallbackRender={({ resetErrorBoundary }) => (\n * <div>\n * There was an error!\n * <button onClick={() => resetErrorBoundary()}>Try again</button>\n * </div>\n * )}\n * >\n * <Page />\n * </ErrorBoundary>\n * )}\n * </QueryErrorResetBoundary>\n * )\n * }\n * ```\n */\nexport const QueryErrorResetBoundary = ({\n children,\n}: QueryErrorResetBoundaryProps) => {\n const [value] = React.useState(() => createValue())\n return (\n <QueryErrorResetBoundaryContext.Provider value={value}>\n {typeof children === 'function' ? children(value) : children}\n </QueryErrorResetBoundaryContext.Provider>\n )\n}\n"],"mappings":";;;;;;;AAiBA,SAAS,cAA4C;CACnD,IAAI,UAAU;CACd,OAAO;;;;EAIL,kBAAkB;GAChB,UAAU;EACZ;;;;EAIA,aAAa;GACX,UAAU;EACZ;;;;EAIA,eAAe;GACb,OAAO;EACT;CACF;AACF;AAEA,MAAM,iCAAiC,MAAM,cAAc,YAAY,CAAC;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAkCxE,MAAa,mCACX,MAAM,WAAW,8BAA8B;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA2DjD,MAAa,2BAA2B,EACtC,eACkC;CAClC,MAAM,CAAC,SAAS,MAAM,eAAe,YAAY,CAAC;CAClD,OACE,oBAAC,+BAA+B,UAAhC;EAAgD;EAC7C,UAAA,OAAO,aAAa,aAAa,SAAS,KAAK,IAAI;CACb,CAAA;AAE7C"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"infiniteQueryOptions.cjs","names":[],"sources":["../../src/infiniteQueryOptions.ts"],"sourcesContent":["import type {\n DefaultError,\n InfiniteData,\n InitialDataFunction,\n NonUndefinedGuard,\n OmitKeyof,\n QueryKey,\n QueryKeyWithDataTag,\n SkipToken,\n} from '@tanstack/query-core'\nimport type { UseInfiniteQueryOptions } from './types'\n\nexport type UndefinedInitialDataInfiniteOptions<\n TQueryFnData,\n TError = DefaultError,\n TData = InfiniteData<TQueryFnData>,\n TQueryKey extends QueryKey = QueryKey,\n TPageParam = unknown,\n> = UseInfiniteQueryOptions<\n TQueryFnData,\n TError,\n TData,\n TQueryKey,\n TPageParam\n> & {\n initialData?:\n | undefined\n | NonUndefinedGuard<InfiniteData<TQueryFnData, TPageParam>>\n | InitialDataFunction<\n NonUndefinedGuard<InfiniteData<TQueryFnData, TPageParam>>\n >\n}\n\nexport type UnusedSkipTokenInfiniteOptions<\n TQueryFnData,\n TError = DefaultError,\n TData = InfiniteData<TQueryFnData>,\n TQueryKey extends QueryKey = QueryKey,\n TPageParam = unknown,\n> = OmitKeyof<\n UseInfiniteQueryOptions<TQueryFnData, TError, TData, TQueryKey, TPageParam>,\n 'queryFn'\n> & {\n queryFn?: Exclude<\n UseInfiniteQueryOptions<\n TQueryFnData,\n TError,\n TData,\n TQueryKey,\n TPageParam\n >['queryFn'],\n SkipToken | undefined\n >\n}\n\nexport type DefinedInitialDataInfiniteOptions<\n TQueryFnData,\n TError = DefaultError,\n TData = InfiniteData<TQueryFnData>,\n TQueryKey extends QueryKey = QueryKey,\n TPageParam = unknown,\n> = UseInfiniteQueryOptions<\n TQueryFnData,\n TError,\n TData,\n TQueryKey,\n TPageParam\n> & {\n initialData:\n | NonUndefinedGuard<InfiniteData<TQueryFnData, TPageParam>>\n | (() => NonUndefinedGuard<InfiniteData<TQueryFnData, TPageParam>>)\n | undefined\n}\n\nexport function infiniteQueryOptions<\n TQueryFnData,\n TError = DefaultError,\n TData = InfiniteData<TQueryFnData>,\n TQueryKey extends QueryKey = QueryKey,\n TPageParam = unknown,\n>(\n options: DefinedInitialDataInfiniteOptions<\n TQueryFnData,\n TError,\n TData,\n TQueryKey,\n TPageParam\n >,\n): DefinedInitialDataInfiniteOptions<\n TQueryFnData,\n TError,\n TData,\n TQueryKey,\n TPageParam\n> &\n QueryKeyWithDataTag<TQueryKey, InfiniteData<TQueryFnData>, TError>\n\nexport function infiniteQueryOptions<\n TQueryFnData,\n TError = DefaultError,\n TData = InfiniteData<TQueryFnData>,\n TQueryKey extends QueryKey = QueryKey,\n TPageParam = unknown,\n>(\n options: UnusedSkipTokenInfiniteOptions<\n TQueryFnData,\n TError,\n TData,\n TQueryKey,\n TPageParam\n >,\n): UnusedSkipTokenInfiniteOptions<\n TQueryFnData,\n TError,\n TData,\n TQueryKey,\n TPageParam\n> &\n QueryKeyWithDataTag<TQueryKey, InfiniteData<TQueryFnData>, TError>\n\nexport function infiniteQueryOptions<\n TQueryFnData,\n TError = DefaultError,\n TData = InfiniteData<TQueryFnData>,\n TQueryKey extends QueryKey = QueryKey,\n TPageParam = unknown,\n>(\n options: UndefinedInitialDataInfiniteOptions<\n TQueryFnData,\n TError,\n TData,\n TQueryKey,\n TPageParam\n >,\n): UndefinedInitialDataInfiniteOptions<\n TQueryFnData,\n TError,\n TData,\n TQueryKey,\n TPageParam\n> &\n QueryKeyWithDataTag<TQueryKey, InfiniteData<TQueryFnData>, TError>\n\nexport function infiniteQueryOptions(options: unknown) {\n return options\n}\n"],"mappings":";;AA+IA,SAAgB,qBAAqB,SAAkB;CACrD,OAAO;AACT"}
|
|
1
|
+
{"version":3,"file":"infiniteQueryOptions.cjs","names":[],"sources":["../../src/infiniteQueryOptions.ts"],"sourcesContent":["import type {\n DefaultError,\n InfiniteData,\n InitialDataFunction,\n NonUndefinedGuard,\n OmitKeyof,\n QueryKey,\n QueryKeyWithDataTag,\n SkipToken,\n} from '@tanstack/query-core'\nimport type { UseInfiniteQueryOptions } from './types'\n\n/**\n * The options accepted by the `infiniteQueryOptions` overload selected when no `initialData` is set — `data`\n * may be `undefined` while the query is `pending`.\n *\n * @template TQueryFnData - The type of a single page, as your `queryFn` resolves it.\n * @template TError - The type of errors your `queryFn` may throw.\n * @template TData - The type `data` ends up as after `select` runs — defaults to `InfiniteData<TQueryFnData>`,\n * the shape of all fetched pages plus their page params.\n * @template TQueryKey - The type of your `queryKey`.\n * @template TPageParam - The type of the parameter passed to `queryFn` to fetch a given page.\n */\nexport type UndefinedInitialDataInfiniteOptions<\n TQueryFnData,\n TError = DefaultError,\n TData = InfiniteData<TQueryFnData>,\n TQueryKey extends QueryKey = QueryKey,\n TPageParam = unknown,\n> = UseInfiniteQueryOptions<\n TQueryFnData,\n TError,\n TData,\n TQueryKey,\n TPageParam\n> & {\n /**\n * If set, this value will be used as the initial data for the query cache (as long as the query hasn't been\n * created or cached yet). If set to a function, the function will be called **once** during the shared/root\n * query initialization, and be expected to synchronously return the initial data. Initial data is\n * considered stale by default unless a `staleTime` has been set. `initialData` **is persisted** to the\n * cache.\n */\n initialData?:\n | undefined\n | NonUndefinedGuard<InfiniteData<TQueryFnData, TPageParam>>\n | InitialDataFunction<\n NonUndefinedGuard<InfiniteData<TQueryFnData, TPageParam>>\n >\n}\n\n/**\n * The options accepted by the `infiniteQueryOptions` overload selected when no `initialData` is set and\n * `queryFn` is not `skipToken` — same as {@link UndefinedInitialDataInfiniteOptions}, but `queryFn` may not be\n * `skipToken`.\n *\n * @template TQueryFnData - The type of a single page, as your `queryFn` resolves it.\n * @template TError - The type of errors your `queryFn` may throw.\n * @template TData - The type `data` ends up as after `select` runs — defaults to `InfiniteData<TQueryFnData>`,\n * the shape of all fetched pages plus their page params.\n * @template TQueryKey - The type of your `queryKey`.\n * @template TPageParam - The type of the parameter passed to `queryFn` to fetch a given page.\n */\nexport type UnusedSkipTokenInfiniteOptions<\n TQueryFnData,\n TError = DefaultError,\n TData = InfiniteData<TQueryFnData>,\n TQueryKey extends QueryKey = QueryKey,\n TPageParam = unknown,\n> = OmitKeyof<\n UseInfiniteQueryOptions<TQueryFnData, TError, TData, TQueryKey, TPageParam>,\n 'queryFn'\n> & {\n /**\n * `skipToken` is not allowed as a value here — this overload is selected when no `initialData` is set. If\n * you don't intend to run the query yet, set `enabled: false` — omitting `queryFn` alone still triggers a\n * fetch that fails with \"Missing queryFn\" unless `enabled` is `false` or a default query function has been\n * defined. A default query function only supplies `queryFn`; it doesn't defer the fetch on its own.\n */\n queryFn?: Exclude<\n UseInfiniteQueryOptions<\n TQueryFnData,\n TError,\n TData,\n TQueryKey,\n TPageParam\n >['queryFn'],\n SkipToken | undefined\n >\n}\n\n/**\n * The options accepted by the `infiniteQueryOptions` overload selected when `initialData` is set — `data` is\n * never `undefined`.\n *\n * @template TQueryFnData - The type of a single page, as your `queryFn` resolves it.\n * @template TError - The type of errors your `queryFn` may throw.\n * @template TData - The type `data` ends up as after `select` runs — defaults to `InfiniteData<TQueryFnData>`,\n * the shape of all fetched pages plus their page params.\n * @template TQueryKey - The type of your `queryKey`.\n * @template TPageParam - The type of the parameter passed to `queryFn` to fetch a given page.\n */\nexport type DefinedInitialDataInfiniteOptions<\n TQueryFnData,\n TError = DefaultError,\n TData = InfiniteData<TQueryFnData>,\n TQueryKey extends QueryKey = QueryKey,\n TPageParam = unknown,\n> = UseInfiniteQueryOptions<\n TQueryFnData,\n TError,\n TData,\n TQueryKey,\n TPageParam\n> & {\n /**\n * If set, this value will be used as the initial data for the query cache (as long as the query hasn't been\n * created or cached yet). If set to a function, the function will be called **once** during the shared/root\n * query initialization, and be expected to synchronously return the initial data. Initial data is\n * considered stale by default unless a `staleTime` has been set. `initialData` **is persisted** to the\n * cache.\n */\n initialData:\n | NonUndefinedGuard<InfiniteData<TQueryFnData, TPageParam>>\n | (() => NonUndefinedGuard<InfiniteData<TQueryFnData, TPageParam>>)\n | undefined\n}\n\n/**\n * You can generally pass everything to `infiniteQueryOptions` that you can also pass to `useInfiniteQuery`.\n * These options can be shared across hooks and imperative APIs such as `queryClient.infiniteQuery`.\n * `options.queryKey` is required and is the query key to generate options for.\n *\n * This overload is selected when `initialData` is set.\n *\n * @see {@link useInfiniteQuery} to run an infinite query with these options.\n * @param options - The {@link DefinedInitialDataInfiniteOptions} to use — everything you can pass to `useInfiniteQuery`, with `initialData` set.\n * @returns The same options object, typed so that `queryKey` carries the inferred data type.\n * @remarks See {@link useInfiniteQuery} for examples that fetch further pages, from a button click or\n * automatically as the user scrolls.\n *\n * @example\n * ```tsx\n * import { infiniteQueryOptions, useInfiniteQuery } from '@tanstack/react-query'\n *\n * export const projectsOptions = infiniteQueryOptions({\n * queryKey: ['projects'],\n * queryFn: ({ pageParam }) => fetchProjects(pageParam),\n * initialPageParam: 0,\n * getNextPageParam: (lastPage) => lastPage.nextId,\n * initialData: { pages: [], pageParams: [] },\n * })\n *\n * function Projects() {\n * // `data` is never `undefined`, thanks to `initialData` — even if a refetch fails, so the\n * // list stays visible alongside the error.\n * const { data, isError, error } = useInfiniteQuery(projectsOptions)\n *\n * return (\n * <div>\n * {isError ? <span>Error: {error.message}</span> : null}\n * <ul>\n * {data.pages.map((page) => page.projects.map((p) => <li key={p.id}>{p.name}</li>))}\n * </ul>\n * </div>\n * )\n * }\n * ```\n */\nexport function infiniteQueryOptions<\n TQueryFnData,\n TError = DefaultError,\n TData = InfiniteData<TQueryFnData>,\n TQueryKey extends QueryKey = QueryKey,\n TPageParam = unknown,\n>(\n options: DefinedInitialDataInfiniteOptions<\n TQueryFnData,\n TError,\n TData,\n TQueryKey,\n TPageParam\n >,\n): DefinedInitialDataInfiniteOptions<\n TQueryFnData,\n TError,\n TData,\n TQueryKey,\n TPageParam\n> &\n QueryKeyWithDataTag<TQueryKey, InfiniteData<TQueryFnData>, TError>\n\n/**\n * You can generally pass everything to `infiniteQueryOptions` that you can also pass to `useInfiniteQuery`.\n * These options can be shared across hooks and imperative APIs such as `queryClient.infiniteQuery`.\n * `options.queryKey` is required and is the query key to generate options for.\n *\n * @returns The same options object, typed so that `queryKey` carries the inferred data type.\n * @remarks See {@link useInfiniteQuery} for examples that fetch further pages, from a button click or\n * automatically as the user scrolls.\n *\n * @example\n * A parameterized factory, so the same options object can be reused per `postId`:\n * ```tsx\n * import { infiniteQueryOptions, useInfiniteQuery } from '@tanstack/react-query'\n *\n * export const commentsOptions = (postId: string) =>\n * infiniteQueryOptions({\n * queryKey: ['post', postId, 'comments'],\n * queryFn: ({ pageParam }) => fetchComments(postId, pageParam),\n * initialPageParam: 0,\n * getNextPageParam: (lastPage) => lastPage.nextId,\n * })\n *\n * function Comments({ postId }: { postId: string }) {\n * const { data, isPending, isError, error } = useInfiniteQuery(commentsOptions(postId))\n *\n * if (isPending) return 'Loading...'\n * if (isError) return <span>Error: {error.message}</span>\n *\n * return (\n * <ul>\n * {data.pages.map((page) => page.comments.map((c) => <li key={c.id}>{c.text}</li>))}\n * </ul>\n * )\n * }\n * ```\n *\n * @see {@link useInfiniteQuery} to run an infinite query with these options.\n * @param options - The {@link UnusedSkipTokenInfiniteOptions} to use — everything you can pass to `useInfiniteQuery`.\n */\nexport function infiniteQueryOptions<\n TQueryFnData,\n TError = DefaultError,\n TData = InfiniteData<TQueryFnData>,\n TQueryKey extends QueryKey = QueryKey,\n TPageParam = unknown,\n>(\n options: UnusedSkipTokenInfiniteOptions<\n TQueryFnData,\n TError,\n TData,\n TQueryKey,\n TPageParam\n >,\n): UnusedSkipTokenInfiniteOptions<\n TQueryFnData,\n TError,\n TData,\n TQueryKey,\n TPageParam\n> &\n QueryKeyWithDataTag<TQueryKey, InfiniteData<TQueryFnData>, TError>\n\n/**\n * You can generally pass everything to `infiniteQueryOptions` that you can also pass to `useInfiniteQuery`.\n * These options can be shared across hooks and imperative APIs such as `queryClient.infiniteQuery`.\n * `options.queryKey` is required and is the query key to generate options for.\n *\n * @returns The same options object, typed so that `queryKey` carries the inferred data type.\n * @remarks See {@link useInfiniteQuery} for examples that fetch further pages (from a button click or\n * automatically as the user scrolls) and that use `skipToken` to disable the query until `postId` is set.\n *\n * @example\n * A parameterized factory, so the same options object can be reused per `postId`:\n * ```tsx\n * import { infiniteQueryOptions, useInfiniteQuery } from '@tanstack/react-query'\n *\n * export const commentsOptions = (postId: string) =>\n * infiniteQueryOptions({\n * queryKey: ['post', postId, 'comments'],\n * queryFn: ({ pageParam }) => fetchComments(postId, pageParam),\n * initialPageParam: 0,\n * getNextPageParam: (lastPage) => lastPage.nextId,\n * })\n *\n * function Comments({ postId }: { postId: string }) {\n * const { data, isPending, isError, error } = useInfiniteQuery(commentsOptions(postId))\n *\n * if (isPending) return 'Loading...'\n * if (isError) return <span>Error: {error.message}</span>\n *\n * return (\n * <ul>\n * {data.pages.map((page) => page.comments.map((c) => <li key={c.id}>{c.text}</li>))}\n * </ul>\n * )\n * }\n * ```\n *\n * @see {@link useInfiniteQuery} to run an infinite query with these options.\n * @param options - The {@link UndefinedInitialDataInfiniteOptions} to use — everything you can pass to `useInfiniteQuery`.\n */\nexport function infiniteQueryOptions<\n TQueryFnData,\n TError = DefaultError,\n TData = InfiniteData<TQueryFnData>,\n TQueryKey extends QueryKey = QueryKey,\n TPageParam = unknown,\n>(\n options: UndefinedInitialDataInfiniteOptions<\n TQueryFnData,\n TError,\n TData,\n TQueryKey,\n TPageParam\n >,\n): UndefinedInitialDataInfiniteOptions<\n TQueryFnData,\n TError,\n TData,\n TQueryKey,\n TPageParam\n> &\n QueryKeyWithDataTag<TQueryKey, InfiniteData<TQueryFnData>, TError>\n\nexport function infiniteQueryOptions(options: unknown) {\n return options\n}\n"],"mappings":";;AA4TA,SAAgB,qBAAqB,SAAkB;CACrD,OAAO;AACT"}
|
|
@@ -1,17 +1,190 @@
|
|
|
1
1
|
import { UseInfiniteQueryOptions } from "./types.cjs";
|
|
2
2
|
import { DefaultError, InfiniteData, InitialDataFunction, NonUndefinedGuard, OmitKeyof, QueryKey, QueryKeyWithDataTag, SkipToken } from "@tanstack/query-core";
|
|
3
3
|
//#region src/infiniteQueryOptions.d.ts
|
|
4
|
+
/**
|
|
5
|
+
* The options accepted by the `infiniteQueryOptions` overload selected when no `initialData` is set — `data`
|
|
6
|
+
* may be `undefined` while the query is `pending`.
|
|
7
|
+
*
|
|
8
|
+
* @template TQueryFnData - The type of a single page, as your `queryFn` resolves it.
|
|
9
|
+
* @template TError - The type of errors your `queryFn` may throw.
|
|
10
|
+
* @template TData - The type `data` ends up as after `select` runs — defaults to `InfiniteData<TQueryFnData>`,
|
|
11
|
+
* the shape of all fetched pages plus their page params.
|
|
12
|
+
* @template TQueryKey - The type of your `queryKey`.
|
|
13
|
+
* @template TPageParam - The type of the parameter passed to `queryFn` to fetch a given page.
|
|
14
|
+
*/
|
|
4
15
|
type UndefinedInitialDataInfiniteOptions<TQueryFnData, TError = DefaultError, TData = InfiniteData<TQueryFnData>, TQueryKey extends QueryKey = QueryKey, TPageParam = unknown> = UseInfiniteQueryOptions<TQueryFnData, TError, TData, TQueryKey, TPageParam> & {
|
|
16
|
+
/**
|
|
17
|
+
* If set, this value will be used as the initial data for the query cache (as long as the query hasn't been
|
|
18
|
+
* created or cached yet). If set to a function, the function will be called **once** during the shared/root
|
|
19
|
+
* query initialization, and be expected to synchronously return the initial data. Initial data is
|
|
20
|
+
* considered stale by default unless a `staleTime` has been set. `initialData` **is persisted** to the
|
|
21
|
+
* cache.
|
|
22
|
+
*/
|
|
5
23
|
initialData?: undefined | NonUndefinedGuard<InfiniteData<TQueryFnData, TPageParam>> | InitialDataFunction<NonUndefinedGuard<InfiniteData<TQueryFnData, TPageParam>>>;
|
|
6
24
|
};
|
|
25
|
+
/**
|
|
26
|
+
* The options accepted by the `infiniteQueryOptions` overload selected when no `initialData` is set and
|
|
27
|
+
* `queryFn` is not `skipToken` — same as {@link UndefinedInitialDataInfiniteOptions}, but `queryFn` may not be
|
|
28
|
+
* `skipToken`.
|
|
29
|
+
*
|
|
30
|
+
* @template TQueryFnData - The type of a single page, as your `queryFn` resolves it.
|
|
31
|
+
* @template TError - The type of errors your `queryFn` may throw.
|
|
32
|
+
* @template TData - The type `data` ends up as after `select` runs — defaults to `InfiniteData<TQueryFnData>`,
|
|
33
|
+
* the shape of all fetched pages plus their page params.
|
|
34
|
+
* @template TQueryKey - The type of your `queryKey`.
|
|
35
|
+
* @template TPageParam - The type of the parameter passed to `queryFn` to fetch a given page.
|
|
36
|
+
*/
|
|
7
37
|
type UnusedSkipTokenInfiniteOptions<TQueryFnData, TError = DefaultError, TData = InfiniteData<TQueryFnData>, TQueryKey extends QueryKey = QueryKey, TPageParam = unknown> = OmitKeyof<UseInfiniteQueryOptions<TQueryFnData, TError, TData, TQueryKey, TPageParam>, 'queryFn'> & {
|
|
38
|
+
/**
|
|
39
|
+
* `skipToken` is not allowed as a value here — this overload is selected when no `initialData` is set. If
|
|
40
|
+
* you don't intend to run the query yet, set `enabled: false` — omitting `queryFn` alone still triggers a
|
|
41
|
+
* fetch that fails with "Missing queryFn" unless `enabled` is `false` or a default query function has been
|
|
42
|
+
* defined. A default query function only supplies `queryFn`; it doesn't defer the fetch on its own.
|
|
43
|
+
*/
|
|
8
44
|
queryFn?: Exclude<UseInfiniteQueryOptions<TQueryFnData, TError, TData, TQueryKey, TPageParam>['queryFn'], SkipToken | undefined>;
|
|
9
45
|
};
|
|
46
|
+
/**
|
|
47
|
+
* The options accepted by the `infiniteQueryOptions` overload selected when `initialData` is set — `data` is
|
|
48
|
+
* never `undefined`.
|
|
49
|
+
*
|
|
50
|
+
* @template TQueryFnData - The type of a single page, as your `queryFn` resolves it.
|
|
51
|
+
* @template TError - The type of errors your `queryFn` may throw.
|
|
52
|
+
* @template TData - The type `data` ends up as after `select` runs — defaults to `InfiniteData<TQueryFnData>`,
|
|
53
|
+
* the shape of all fetched pages plus their page params.
|
|
54
|
+
* @template TQueryKey - The type of your `queryKey`.
|
|
55
|
+
* @template TPageParam - The type of the parameter passed to `queryFn` to fetch a given page.
|
|
56
|
+
*/
|
|
10
57
|
type DefinedInitialDataInfiniteOptions<TQueryFnData, TError = DefaultError, TData = InfiniteData<TQueryFnData>, TQueryKey extends QueryKey = QueryKey, TPageParam = unknown> = UseInfiniteQueryOptions<TQueryFnData, TError, TData, TQueryKey, TPageParam> & {
|
|
58
|
+
/**
|
|
59
|
+
* If set, this value will be used as the initial data for the query cache (as long as the query hasn't been
|
|
60
|
+
* created or cached yet). If set to a function, the function will be called **once** during the shared/root
|
|
61
|
+
* query initialization, and be expected to synchronously return the initial data. Initial data is
|
|
62
|
+
* considered stale by default unless a `staleTime` has been set. `initialData` **is persisted** to the
|
|
63
|
+
* cache.
|
|
64
|
+
*/
|
|
11
65
|
initialData: NonUndefinedGuard<InfiniteData<TQueryFnData, TPageParam>> | (() => NonUndefinedGuard<InfiniteData<TQueryFnData, TPageParam>>) | undefined;
|
|
12
66
|
};
|
|
67
|
+
/**
|
|
68
|
+
* You can generally pass everything to `infiniteQueryOptions` that you can also pass to `useInfiniteQuery`.
|
|
69
|
+
* These options can be shared across hooks and imperative APIs such as `queryClient.infiniteQuery`.
|
|
70
|
+
* `options.queryKey` is required and is the query key to generate options for.
|
|
71
|
+
*
|
|
72
|
+
* This overload is selected when `initialData` is set.
|
|
73
|
+
*
|
|
74
|
+
* @see {@link useInfiniteQuery} to run an infinite query with these options.
|
|
75
|
+
* @param options - The {@link DefinedInitialDataInfiniteOptions} to use — everything you can pass to `useInfiniteQuery`, with `initialData` set.
|
|
76
|
+
* @returns The same options object, typed so that `queryKey` carries the inferred data type.
|
|
77
|
+
* @remarks See {@link useInfiniteQuery} for examples that fetch further pages, from a button click or
|
|
78
|
+
* automatically as the user scrolls.
|
|
79
|
+
*
|
|
80
|
+
* @example
|
|
81
|
+
* ```tsx
|
|
82
|
+
* import { infiniteQueryOptions, useInfiniteQuery } from '@tanstack/react-query'
|
|
83
|
+
*
|
|
84
|
+
* export const projectsOptions = infiniteQueryOptions({
|
|
85
|
+
* queryKey: ['projects'],
|
|
86
|
+
* queryFn: ({ pageParam }) => fetchProjects(pageParam),
|
|
87
|
+
* initialPageParam: 0,
|
|
88
|
+
* getNextPageParam: (lastPage) => lastPage.nextId,
|
|
89
|
+
* initialData: { pages: [], pageParams: [] },
|
|
90
|
+
* })
|
|
91
|
+
*
|
|
92
|
+
* function Projects() {
|
|
93
|
+
* // `data` is never `undefined`, thanks to `initialData` — even if a refetch fails, so the
|
|
94
|
+
* // list stays visible alongside the error.
|
|
95
|
+
* const { data, isError, error } = useInfiniteQuery(projectsOptions)
|
|
96
|
+
*
|
|
97
|
+
* return (
|
|
98
|
+
* <div>
|
|
99
|
+
* {isError ? <span>Error: {error.message}</span> : null}
|
|
100
|
+
* <ul>
|
|
101
|
+
* {data.pages.map((page) => page.projects.map((p) => <li key={p.id}>{p.name}</li>))}
|
|
102
|
+
* </ul>
|
|
103
|
+
* </div>
|
|
104
|
+
* )
|
|
105
|
+
* }
|
|
106
|
+
* ```
|
|
107
|
+
*/
|
|
13
108
|
declare function infiniteQueryOptions<TQueryFnData, TError = DefaultError, TData = InfiniteData<TQueryFnData>, TQueryKey extends QueryKey = QueryKey, TPageParam = unknown>(options: DefinedInitialDataInfiniteOptions<TQueryFnData, TError, TData, TQueryKey, TPageParam>): DefinedInitialDataInfiniteOptions<TQueryFnData, TError, TData, TQueryKey, TPageParam> & QueryKeyWithDataTag<TQueryKey, InfiniteData<TQueryFnData>, TError>;
|
|
109
|
+
/**
|
|
110
|
+
* You can generally pass everything to `infiniteQueryOptions` that you can also pass to `useInfiniteQuery`.
|
|
111
|
+
* These options can be shared across hooks and imperative APIs such as `queryClient.infiniteQuery`.
|
|
112
|
+
* `options.queryKey` is required and is the query key to generate options for.
|
|
113
|
+
*
|
|
114
|
+
* @returns The same options object, typed so that `queryKey` carries the inferred data type.
|
|
115
|
+
* @remarks See {@link useInfiniteQuery} for examples that fetch further pages, from a button click or
|
|
116
|
+
* automatically as the user scrolls.
|
|
117
|
+
*
|
|
118
|
+
* @example
|
|
119
|
+
* A parameterized factory, so the same options object can be reused per `postId`:
|
|
120
|
+
* ```tsx
|
|
121
|
+
* import { infiniteQueryOptions, useInfiniteQuery } from '@tanstack/react-query'
|
|
122
|
+
*
|
|
123
|
+
* export const commentsOptions = (postId: string) =>
|
|
124
|
+
* infiniteQueryOptions({
|
|
125
|
+
* queryKey: ['post', postId, 'comments'],
|
|
126
|
+
* queryFn: ({ pageParam }) => fetchComments(postId, pageParam),
|
|
127
|
+
* initialPageParam: 0,
|
|
128
|
+
* getNextPageParam: (lastPage) => lastPage.nextId,
|
|
129
|
+
* })
|
|
130
|
+
*
|
|
131
|
+
* function Comments({ postId }: { postId: string }) {
|
|
132
|
+
* const { data, isPending, isError, error } = useInfiniteQuery(commentsOptions(postId))
|
|
133
|
+
*
|
|
134
|
+
* if (isPending) return 'Loading...'
|
|
135
|
+
* if (isError) return <span>Error: {error.message}</span>
|
|
136
|
+
*
|
|
137
|
+
* return (
|
|
138
|
+
* <ul>
|
|
139
|
+
* {data.pages.map((page) => page.comments.map((c) => <li key={c.id}>{c.text}</li>))}
|
|
140
|
+
* </ul>
|
|
141
|
+
* )
|
|
142
|
+
* }
|
|
143
|
+
* ```
|
|
144
|
+
*
|
|
145
|
+
* @see {@link useInfiniteQuery} to run an infinite query with these options.
|
|
146
|
+
* @param options - The {@link UnusedSkipTokenInfiniteOptions} to use — everything you can pass to `useInfiniteQuery`.
|
|
147
|
+
*/
|
|
14
148
|
declare function infiniteQueryOptions<TQueryFnData, TError = DefaultError, TData = InfiniteData<TQueryFnData>, TQueryKey extends QueryKey = QueryKey, TPageParam = unknown>(options: UnusedSkipTokenInfiniteOptions<TQueryFnData, TError, TData, TQueryKey, TPageParam>): UnusedSkipTokenInfiniteOptions<TQueryFnData, TError, TData, TQueryKey, TPageParam> & QueryKeyWithDataTag<TQueryKey, InfiniteData<TQueryFnData>, TError>;
|
|
149
|
+
/**
|
|
150
|
+
* You can generally pass everything to `infiniteQueryOptions` that you can also pass to `useInfiniteQuery`.
|
|
151
|
+
* These options can be shared across hooks and imperative APIs such as `queryClient.infiniteQuery`.
|
|
152
|
+
* `options.queryKey` is required and is the query key to generate options for.
|
|
153
|
+
*
|
|
154
|
+
* @returns The same options object, typed so that `queryKey` carries the inferred data type.
|
|
155
|
+
* @remarks See {@link useInfiniteQuery} for examples that fetch further pages (from a button click or
|
|
156
|
+
* automatically as the user scrolls) and that use `skipToken` to disable the query until `postId` is set.
|
|
157
|
+
*
|
|
158
|
+
* @example
|
|
159
|
+
* A parameterized factory, so the same options object can be reused per `postId`:
|
|
160
|
+
* ```tsx
|
|
161
|
+
* import { infiniteQueryOptions, useInfiniteQuery } from '@tanstack/react-query'
|
|
162
|
+
*
|
|
163
|
+
* export const commentsOptions = (postId: string) =>
|
|
164
|
+
* infiniteQueryOptions({
|
|
165
|
+
* queryKey: ['post', postId, 'comments'],
|
|
166
|
+
* queryFn: ({ pageParam }) => fetchComments(postId, pageParam),
|
|
167
|
+
* initialPageParam: 0,
|
|
168
|
+
* getNextPageParam: (lastPage) => lastPage.nextId,
|
|
169
|
+
* })
|
|
170
|
+
*
|
|
171
|
+
* function Comments({ postId }: { postId: string }) {
|
|
172
|
+
* const { data, isPending, isError, error } = useInfiniteQuery(commentsOptions(postId))
|
|
173
|
+
*
|
|
174
|
+
* if (isPending) return 'Loading...'
|
|
175
|
+
* if (isError) return <span>Error: {error.message}</span>
|
|
176
|
+
*
|
|
177
|
+
* return (
|
|
178
|
+
* <ul>
|
|
179
|
+
* {data.pages.map((page) => page.comments.map((c) => <li key={c.id}>{c.text}</li>))}
|
|
180
|
+
* </ul>
|
|
181
|
+
* )
|
|
182
|
+
* }
|
|
183
|
+
* ```
|
|
184
|
+
*
|
|
185
|
+
* @see {@link useInfiniteQuery} to run an infinite query with these options.
|
|
186
|
+
* @param options - The {@link UndefinedInitialDataInfiniteOptions} to use — everything you can pass to `useInfiniteQuery`.
|
|
187
|
+
*/
|
|
15
188
|
declare function infiniteQueryOptions<TQueryFnData, TError = DefaultError, TData = InfiniteData<TQueryFnData>, TQueryKey extends QueryKey = QueryKey, TPageParam = unknown>(options: UndefinedInitialDataInfiniteOptions<TQueryFnData, TError, TData, TQueryKey, TPageParam>): UndefinedInitialDataInfiniteOptions<TQueryFnData, TError, TData, TQueryKey, TPageParam> & QueryKeyWithDataTag<TQueryKey, InfiniteData<TQueryFnData>, TError>;
|
|
16
189
|
//#endregion
|
|
17
190
|
export { DefinedInitialDataInfiniteOptions, UndefinedInitialDataInfiniteOptions, UnusedSkipTokenInfiniteOptions, infiniteQueryOptions };
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"infiniteQueryOptions.d.cts","names":[],"sources":["../../src/infiniteQueryOptions.ts"],"mappings":"
|
|
1
|
+
{"version":3,"file":"infiniteQueryOptions.d.cts","names":[],"sources":["../../src/infiniteQueryOptions.ts"],"mappings":";;;;;;;;;;;;;;KAuBY,oCACV,cACA,SAAS,cACT,QAAQ,aAAa,eACrB,kBAAkB,WAAW,UAC7B,wBACE,wBACF,cACA,QACA,OACA,WACA;;;;;;;;EASA,0BAEI,kBAAkB,aAAa,cAAc,eAC7C,oBACE,kBAAkB,aAAa,cAAc;;;;;;;;;;;;;;KAgBzC,+BACV,cACA,SAAS,cACT,QAAQ,aAAa,eACrB,kBAAkB,WAAW,UAC7B,wBACE,UACF,wBAAwB,cAAc,QAAQ,OAAO,WAAW;;;;;;;EAShE,UAAU,QACR,wBACE,cACA,QACA,OACA,WACA,wBAEF;;;;;;;;;;;;;KAeQ,kCACV,cACA,SAAS,cACT,QAAQ,aAAa,eACrB,kBAAkB,WAAW,UAC7B,wBACE,wBACF,cACA,QACA,OACA,WACA;;;;;;;;EASA,aACI,kBAAkB,aAAa,cAAc,sBACtC,kBAAkB,aAAa,cAAc;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;iBA6C1C,qBACd,cACA,SAAS,cACT,QAAQ,aAAa,eACrB,kBAAkB,WAAW,UAC7B,sBAEA,SAAS,kCACP,cACA,QACA,OACA,WACA,cAED,kCACD,cACA,QACA,OACA,WACA,cAEA,oBAAoB,WAAW,aAAa,eAAe;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;iBAyC7C,qBACd,cACA,SAAS,cACT,QAAQ,aAAa,eACrB,kBAAkB,WAAW,UAC7B,sBAEA,SAAS,+BACP,cACA,QACA,OACA,WACA,cAED,+BACD,cACA,QACA,OACA,WACA,cAEA,oBAAoB,WAAW,aAAa,eAAe;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;iBAyC7C,qBACd,cACA,SAAS,cACT,QAAQ,aAAa,eACrB,kBAAkB,WAAW,UAC7B,sBAEA,SAAS,oCACP,cACA,QACA,OACA,WACA,cAED,oCACD,cACA,QACA,OACA,WACA,cAEA,oBAAoB,WAAW,aAAa,eAAe"}
|