@tanstack/preact-query 5.102.2 → 5.102.4
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 +75 -0
- package/build/legacy/QueryErrorResetBoundary.cjs.map +1 -1
- package/build/legacy/QueryErrorResetBoundary.d.cts +106 -0
- package/build/legacy/QueryErrorResetBoundary.d.cts.map +1 -1
- package/build/legacy/QueryErrorResetBoundary.d.ts +106 -0
- package/build/legacy/QueryErrorResetBoundary.d.ts.map +1 -1
- package/build/legacy/QueryErrorResetBoundary.js +75 -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 +116 -0
- package/build/legacy/useInfiniteQuery.d.cts.map +1 -1
- package/build/legacy/useInfiniteQuery.d.ts +116 -0
- package/build/legacy/useInfiniteQuery.d.ts.map +1 -1
- package/build/legacy/useInfiniteQuery.js.map +1 -1
- package/build/legacy/useIsFetching.cjs +20 -0
- package/build/legacy/useIsFetching.cjs.map +1 -1
- package/build/legacy/useIsFetching.d.cts +20 -0
- package/build/legacy/useIsFetching.d.cts.map +1 -1
- package/build/legacy/useIsFetching.d.ts +20 -0
- package/build/legacy/useIsFetching.d.ts.map +1 -1
- package/build/legacy/useIsFetching.js +20 -0
- package/build/legacy/useIsFetching.js.map +1 -1
- package/build/legacy/useMutation.cjs +67 -0
- package/build/legacy/useMutation.cjs.map +1 -1
- package/build/legacy/useMutation.d.cts +67 -0
- package/build/legacy/useMutation.d.cts.map +1 -1
- package/build/legacy/useMutation.d.ts +67 -0
- package/build/legacy/useMutation.d.ts.map +1 -1
- package/build/legacy/useMutation.js +67 -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 +36 -1
- 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 +36 -1
- 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 +134 -0
- package/build/legacy/useQuery.d.cts.map +1 -1
- package/build/legacy/useQuery.d.ts +134 -0
- package/build/legacy/useQuery.d.ts.map +1 -1
- package/build/legacy/useQuery.js.map +1 -1
- package/build/legacy/useSuspenseInfiniteQuery.cjs +48 -0
- package/build/legacy/useSuspenseInfiniteQuery.cjs.map +1 -1
- package/build/legacy/useSuspenseInfiniteQuery.d.cts +48 -0
- package/build/legacy/useSuspenseInfiniteQuery.d.cts.map +1 -1
- package/build/legacy/useSuspenseInfiniteQuery.d.ts +48 -0
- package/build/legacy/useSuspenseInfiniteQuery.d.ts.map +1 -1
- package/build/legacy/useSuspenseInfiniteQuery.js +48 -0
- package/build/legacy/useSuspenseInfiniteQuery.js.map +1 -1
- package/build/legacy/useSuspenseQueries.cjs.map +1 -1
- package/build/legacy/useSuspenseQueries.d.cts +128 -2
- package/build/legacy/useSuspenseQueries.d.cts.map +1 -1
- package/build/legacy/useSuspenseQueries.d.ts +128 -2
- package/build/legacy/useSuspenseQueries.d.ts.map +1 -1
- package/build/legacy/useSuspenseQueries.js.map +1 -1
- package/build/legacy/useSuspenseQuery.cjs +43 -0
- package/build/legacy/useSuspenseQuery.cjs.map +1 -1
- package/build/legacy/useSuspenseQuery.d.cts +43 -0
- package/build/legacy/useSuspenseQuery.d.cts.map +1 -1
- package/build/legacy/useSuspenseQuery.d.ts +43 -0
- package/build/legacy/useSuspenseQuery.d.ts.map +1 -1
- package/build/legacy/useSuspenseQuery.js +43 -0
- package/build/legacy/useSuspenseQuery.js.map +1 -1
- package/build/legacy/utils.cjs.map +1 -1
- package/build/legacy/utils.d.cts.map +1 -1
- package/build/legacy/utils.d.ts.map +1 -1
- package/build/legacy/utils.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 +75 -0
- package/build/modern/QueryErrorResetBoundary.cjs.map +1 -1
- package/build/modern/QueryErrorResetBoundary.d.cts +106 -0
- package/build/modern/QueryErrorResetBoundary.d.cts.map +1 -1
- package/build/modern/QueryErrorResetBoundary.d.ts +106 -0
- package/build/modern/QueryErrorResetBoundary.d.ts.map +1 -1
- package/build/modern/QueryErrorResetBoundary.js +75 -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 +116 -0
- package/build/modern/useInfiniteQuery.d.cts.map +1 -1
- package/build/modern/useInfiniteQuery.d.ts +116 -0
- package/build/modern/useInfiniteQuery.d.ts.map +1 -1
- package/build/modern/useInfiniteQuery.js.map +1 -1
- package/build/modern/useIsFetching.cjs +20 -0
- package/build/modern/useIsFetching.cjs.map +1 -1
- package/build/modern/useIsFetching.d.cts +20 -0
- package/build/modern/useIsFetching.d.cts.map +1 -1
- package/build/modern/useIsFetching.d.ts +20 -0
- package/build/modern/useIsFetching.d.ts.map +1 -1
- package/build/modern/useIsFetching.js +20 -0
- package/build/modern/useIsFetching.js.map +1 -1
- package/build/modern/useMutation.cjs +67 -0
- package/build/modern/useMutation.cjs.map +1 -1
- package/build/modern/useMutation.d.cts +67 -0
- package/build/modern/useMutation.d.cts.map +1 -1
- package/build/modern/useMutation.d.ts +67 -0
- package/build/modern/useMutation.d.ts.map +1 -1
- package/build/modern/useMutation.js +67 -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 +36 -1
- 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 +36 -1
- 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 +134 -0
- package/build/modern/useQuery.d.cts.map +1 -1
- package/build/modern/useQuery.d.ts +134 -0
- package/build/modern/useQuery.d.ts.map +1 -1
- package/build/modern/useQuery.js.map +1 -1
- package/build/modern/useSuspenseInfiniteQuery.cjs +48 -0
- package/build/modern/useSuspenseInfiniteQuery.cjs.map +1 -1
- package/build/modern/useSuspenseInfiniteQuery.d.cts +48 -0
- package/build/modern/useSuspenseInfiniteQuery.d.cts.map +1 -1
- package/build/modern/useSuspenseInfiniteQuery.d.ts +48 -0
- package/build/modern/useSuspenseInfiniteQuery.d.ts.map +1 -1
- package/build/modern/useSuspenseInfiniteQuery.js +48 -0
- package/build/modern/useSuspenseInfiniteQuery.js.map +1 -1
- package/build/modern/useSuspenseQueries.cjs.map +1 -1
- package/build/modern/useSuspenseQueries.d.cts +128 -2
- package/build/modern/useSuspenseQueries.d.cts.map +1 -1
- package/build/modern/useSuspenseQueries.d.ts +128 -2
- package/build/modern/useSuspenseQueries.d.ts.map +1 -1
- package/build/modern/useSuspenseQueries.js.map +1 -1
- package/build/modern/useSuspenseQuery.cjs +43 -0
- package/build/modern/useSuspenseQuery.cjs.map +1 -1
- package/build/modern/useSuspenseQuery.d.cts +43 -0
- package/build/modern/useSuspenseQuery.d.cts.map +1 -1
- package/build/modern/useSuspenseQuery.d.ts +43 -0
- package/build/modern/useSuspenseQuery.d.ts.map +1 -1
- package/build/modern/useSuspenseQuery.js +43 -0
- package/build/modern/useSuspenseQuery.js.map +1 -1
- package/build/modern/utils.cjs.map +1 -1
- package/build/modern/utils.d.cts.map +1 -1
- package/build/modern/utils.d.ts.map +1 -1
- package/build/modern/utils.js.map +1 -1
- package/package.json +3 -3
- package/src/HydrationBoundary.tsx +61 -1
- package/src/IsRestoringProvider.ts +12 -0
- package/src/QueryClientProvider.tsx +41 -0
- package/src/QueryErrorResetBoundary.tsx +109 -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 +116 -0
- package/src/useIsFetching.ts +20 -0
- package/src/useMutation.ts +67 -0
- package/src/useMutationState.ts +74 -0
- package/src/usePrefetchInfiniteQuery.tsx +44 -0
- package/src/usePrefetchQuery.tsx +36 -1
- package/src/useQueries.ts +85 -2
- package/src/useQuery.ts +134 -0
- package/src/useSuspenseInfiniteQuery.ts +48 -0
- package/src/useSuspenseQueries.ts +128 -2
- package/src/useSuspenseQuery.ts +43 -0
- package/src/utils.ts +0 -1
|
@@ -18,7 +18,82 @@ function createValue() {
|
|
|
18
18
|
};
|
|
19
19
|
}
|
|
20
20
|
const QueryErrorResetBoundaryContext = (0, preact.createContext)(createValue());
|
|
21
|
+
/**
|
|
22
|
+
* This hook will reset any query errors within the closest `QueryErrorResetBoundary`. If there is no boundary
|
|
23
|
+
* defined it will reset them globally.
|
|
24
|
+
*
|
|
25
|
+
* @returns The boundary's {@link QueryErrorResetBoundaryValue}.
|
|
26
|
+
*
|
|
27
|
+
* @example
|
|
28
|
+
* ```tsx
|
|
29
|
+
* import { useErrorBoundary } from 'preact/hooks'
|
|
30
|
+
* import type { ComponentChildren } from 'preact'
|
|
31
|
+
* import { useQueryErrorResetBoundary } from '@tanstack/preact-query'
|
|
32
|
+
*
|
|
33
|
+
* function App({ children }: { children: ComponentChildren }) {
|
|
34
|
+
* const { reset } = useQueryErrorResetBoundary()
|
|
35
|
+
* const [error, resetError] = useErrorBoundary(() => reset())
|
|
36
|
+
*
|
|
37
|
+
* if (error) {
|
|
38
|
+
* return (
|
|
39
|
+
* <div>
|
|
40
|
+
* There was an error!
|
|
41
|
+
* <button onClick={() => resetError()}>Try again</button>
|
|
42
|
+
* </div>
|
|
43
|
+
* )
|
|
44
|
+
* }
|
|
45
|
+
*
|
|
46
|
+
* return children
|
|
47
|
+
* }
|
|
48
|
+
* ```
|
|
49
|
+
*/
|
|
21
50
|
const useQueryErrorResetBoundary = () => (0, preact_hooks.useContext)(QueryErrorResetBoundaryContext);
|
|
51
|
+
/**
|
|
52
|
+
* When using `suspense` or `throwOnError` in your queries, you need a way to let queries know that you want to
|
|
53
|
+
* try again when re-rendering after some error occurred. With the `QueryErrorResetBoundary` component you can
|
|
54
|
+
* reset any query errors within the boundaries of the component.
|
|
55
|
+
*
|
|
56
|
+
* @returns The `children`, rendered as-is, or called with the boundary's {@link QueryErrorResetBoundaryValue}
|
|
57
|
+
* if `children` is a function.
|
|
58
|
+
*
|
|
59
|
+
* @example
|
|
60
|
+
* ```tsx
|
|
61
|
+
* import { useErrorBoundary } from 'preact/hooks'
|
|
62
|
+
* import type { ComponentChildren } from 'preact'
|
|
63
|
+
* import { QueryErrorResetBoundary } from '@tanstack/preact-query'
|
|
64
|
+
*
|
|
65
|
+
* function ErrorBoundary({
|
|
66
|
+
* children,
|
|
67
|
+
* reset,
|
|
68
|
+
* }: {
|
|
69
|
+
* children: ComponentChildren
|
|
70
|
+
* reset: () => void
|
|
71
|
+
* }) {
|
|
72
|
+
* const [error, resetError] = useErrorBoundary(() => reset())
|
|
73
|
+
*
|
|
74
|
+
* if (error) {
|
|
75
|
+
* return (
|
|
76
|
+
* <div>
|
|
77
|
+
* There was an error!
|
|
78
|
+
* <button onClick={() => resetError()}>Try again</button>
|
|
79
|
+
* </div>
|
|
80
|
+
* )
|
|
81
|
+
* }
|
|
82
|
+
*
|
|
83
|
+
* return children
|
|
84
|
+
* }
|
|
85
|
+
*
|
|
86
|
+
* const App = () => (
|
|
87
|
+
* <QueryErrorResetBoundary>
|
|
88
|
+
* {({ reset }) => (
|
|
89
|
+
* <ErrorBoundary reset={reset}>
|
|
90
|
+
* <Page />
|
|
91
|
+
* </ErrorBoundary>
|
|
92
|
+
* )}
|
|
93
|
+
* </QueryErrorResetBoundary>
|
|
94
|
+
* )
|
|
95
|
+
* ```
|
|
96
|
+
*/
|
|
22
97
|
const QueryErrorResetBoundary = ({ children }) => {
|
|
23
98
|
const [value] = (0, preact_hooks.useState)(() => createValue());
|
|
24
99
|
return /* @__PURE__ */ (0, preact_jsx_runtime.jsx)(QueryErrorResetBoundaryContext.Provider, {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"QueryErrorResetBoundary.cjs","names":["createContext","useContext","useState"],"sources":["../../src/QueryErrorResetBoundary.tsx"],"sourcesContent":["import { createContext } from 'preact'\nimport type { ComponentChildren } from 'preact'\nimport { useContext, useState } from 'preact/hooks'\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 = createContext(createValue())\n\n// HOOK\n\nexport const useQueryErrorResetBoundary = () =>\n useContext(QueryErrorResetBoundaryContext)\n\n// COMPONENT\n\nexport type QueryErrorResetBoundaryFunction = (\n value: QueryErrorResetBoundaryValue,\n) => ComponentChildren\n\nexport interface QueryErrorResetBoundaryProps {\n children: QueryErrorResetBoundaryFunction | ComponentChildren\n}\n\nexport const QueryErrorResetBoundary = ({\n children,\n}: QueryErrorResetBoundaryProps) => {\n const [value] = 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.cjs","names":["createContext","useContext","useState"],"sources":["../../src/QueryErrorResetBoundary.tsx"],"sourcesContent":["import { createContext } from 'preact'\nimport type { ComponentChildren } from 'preact'\nimport { useContext, useState } from 'preact/hooks'\n\n// CONTEXT\n\n/**\n * Resets any query errors within the boundary, so queries know they can try again.\n */\nexport type QueryErrorResetFunction = () => void\n\n/**\n * Returns whether the boundary has been reset and not yet cleared.\n */\nexport type QueryErrorIsResetFunction = () => boolean\n\n/**\n * Clears the reset state, so queries know not to try again until the boundary is reset again.\n */\nexport type QueryErrorClearResetFunction = () => void\n\nexport interface QueryErrorResetBoundaryValue {\n /**\n * Clears the reset state, so queries know not to try again until the boundary is reset again.\n */\n clearReset: QueryErrorClearResetFunction\n /**\n * Returns whether the boundary has been reset and not yet cleared.\n */\n isReset: QueryErrorIsResetFunction\n /**\n * Resets any query errors within the boundary, so queries know they can try again.\n */\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 = 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 { useErrorBoundary } from 'preact/hooks'\n * import type { ComponentChildren } from 'preact'\n * import { useQueryErrorResetBoundary } from '@tanstack/preact-query'\n *\n * function App({ children }: { children: ComponentChildren }) {\n * const { reset } = useQueryErrorResetBoundary()\n * const [error, resetError] = useErrorBoundary(() => reset())\n *\n * if (error) {\n * return (\n * <div>\n * There was an error!\n * <button onClick={() => resetError()}>Try again</button>\n * </div>\n * )\n * }\n *\n * return children\n * }\n * ```\n */\nexport const useQueryErrorResetBoundary = () =>\n 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) => ComponentChildren\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 | ComponentChildren\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 { useErrorBoundary } from 'preact/hooks'\n * import type { ComponentChildren } from 'preact'\n * import { QueryErrorResetBoundary } from '@tanstack/preact-query'\n *\n * function ErrorBoundary({\n * children,\n * reset,\n * }: {\n * children: ComponentChildren\n * reset: () => void\n * }) {\n * const [error, resetError] = useErrorBoundary(() => reset())\n *\n * if (error) {\n * return (\n * <div>\n * There was an error!\n * <button onClick={() => resetError()}>Try again</button>\n * </div>\n * )\n * }\n *\n * return children\n * }\n *\n * const App = () => (\n * <QueryErrorResetBoundary>\n * {({ reset }) => (\n * <ErrorBoundary reset={reset}>\n * <Page />\n * </ErrorBoundary>\n * )}\n * </QueryErrorResetBoundary>\n * )\n * ```\n */\nexport const QueryErrorResetBoundary = ({\n children,\n}: QueryErrorResetBoundaryProps) => {\n const [value] = useState(() => createValue())\n return (\n <QueryErrorResetBoundaryContext.Provider value={value}>\n {typeof children === 'function' ? children(value) : children}\n </QueryErrorResetBoundaryContext.Provider>\n )\n}\n"],"mappings":";;;;;AAoCA,SAAS,cAA4C;CACnD,IAAI,UAAU;CACd,OAAO;EACL,kBAAkB;GAChB,UAAU;EACZ;EACA,aAAa;GACX,UAAU;EACZ;EACA,eAAe;GACb,OAAO;EACT;CACF;AACF;AAEA,MAAM,kCAAA,GAAiCA,OAAAA,cAAAA,CAAc,YAAY,CAAC;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAiClE,MAAa,oCAAA,GACXC,aAAAA,WAAAA,CAAW,8BAA8B;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAuE3C,MAAa,2BAA2B,EACtC,eACkC;CAClC,MAAM,CAAC,UAAA,GAASC,aAAAA,SAAAA,OAAe,YAAY,CAAC;CAC5C,OACE,iBAAA,GAAA,mBAAA,IAAA,CAAC,+BAA+B,UAAhC;EAAgD;EAC7C,UAAA,OAAO,aAAa,aAAa,SAAS,KAAK,IAAI;CACb,CAAA;AAE7C"}
|
|
@@ -1,18 +1,124 @@
|
|
|
1
1
|
import { ComponentChildren } from "preact";
|
|
2
2
|
//#region src/QueryErrorResetBoundary.d.ts
|
|
3
|
+
/**
|
|
4
|
+
* Resets any query errors within the boundary, so queries know they can try again.
|
|
5
|
+
*/
|
|
3
6
|
type QueryErrorResetFunction = () => void;
|
|
7
|
+
/**
|
|
8
|
+
* Returns whether the boundary has been reset and not yet cleared.
|
|
9
|
+
*/
|
|
4
10
|
type QueryErrorIsResetFunction = () => boolean;
|
|
11
|
+
/**
|
|
12
|
+
* Clears the reset state, so queries know not to try again until the boundary is reset again.
|
|
13
|
+
*/
|
|
5
14
|
type QueryErrorClearResetFunction = () => void;
|
|
6
15
|
interface QueryErrorResetBoundaryValue {
|
|
16
|
+
/**
|
|
17
|
+
* Clears the reset state, so queries know not to try again until the boundary is reset again.
|
|
18
|
+
*/
|
|
7
19
|
clearReset: QueryErrorClearResetFunction;
|
|
20
|
+
/**
|
|
21
|
+
* Returns whether the boundary has been reset and not yet cleared.
|
|
22
|
+
*/
|
|
8
23
|
isReset: QueryErrorIsResetFunction;
|
|
24
|
+
/**
|
|
25
|
+
* Resets any query errors within the boundary, so queries know they can try again.
|
|
26
|
+
*/
|
|
9
27
|
reset: QueryErrorResetFunction;
|
|
10
28
|
}
|
|
29
|
+
/**
|
|
30
|
+
* This hook will reset any query errors within the closest `QueryErrorResetBoundary`. If there is no boundary
|
|
31
|
+
* defined it will reset them globally.
|
|
32
|
+
*
|
|
33
|
+
* @returns The boundary's {@link QueryErrorResetBoundaryValue}.
|
|
34
|
+
*
|
|
35
|
+
* @example
|
|
36
|
+
* ```tsx
|
|
37
|
+
* import { useErrorBoundary } from 'preact/hooks'
|
|
38
|
+
* import type { ComponentChildren } from 'preact'
|
|
39
|
+
* import { useQueryErrorResetBoundary } from '@tanstack/preact-query'
|
|
40
|
+
*
|
|
41
|
+
* function App({ children }: { children: ComponentChildren }) {
|
|
42
|
+
* const { reset } = useQueryErrorResetBoundary()
|
|
43
|
+
* const [error, resetError] = useErrorBoundary(() => reset())
|
|
44
|
+
*
|
|
45
|
+
* if (error) {
|
|
46
|
+
* return (
|
|
47
|
+
* <div>
|
|
48
|
+
* There was an error!
|
|
49
|
+
* <button onClick={() => resetError()}>Try again</button>
|
|
50
|
+
* </div>
|
|
51
|
+
* )
|
|
52
|
+
* }
|
|
53
|
+
*
|
|
54
|
+
* return children
|
|
55
|
+
* }
|
|
56
|
+
* ```
|
|
57
|
+
*/
|
|
11
58
|
declare const useQueryErrorResetBoundary: () => QueryErrorResetBoundaryValue;
|
|
59
|
+
/**
|
|
60
|
+
* A render-prop function usable as `children` on `QueryErrorResetBoundary`.
|
|
61
|
+
*
|
|
62
|
+
* @param value - The boundary's {@link QueryErrorResetBoundaryValue}.
|
|
63
|
+
* @returns The children to render.
|
|
64
|
+
*/
|
|
12
65
|
type QueryErrorResetBoundaryFunction = (value: QueryErrorResetBoundaryValue) => ComponentChildren;
|
|
66
|
+
/**
|
|
67
|
+
* The props accepted by `QueryErrorResetBoundary`.
|
|
68
|
+
*/
|
|
13
69
|
interface QueryErrorResetBoundaryProps {
|
|
70
|
+
/**
|
|
71
|
+
* Either a plain node, or a function that receives the boundary's {@link QueryErrorResetBoundaryValue} and
|
|
72
|
+
* returns a node.
|
|
73
|
+
*/
|
|
14
74
|
children: QueryErrorResetBoundaryFunction | ComponentChildren;
|
|
15
75
|
}
|
|
76
|
+
/**
|
|
77
|
+
* When using `suspense` or `throwOnError` in your queries, you need a way to let queries know that you want to
|
|
78
|
+
* try again when re-rendering after some error occurred. With the `QueryErrorResetBoundary` component you can
|
|
79
|
+
* reset any query errors within the boundaries of the component.
|
|
80
|
+
*
|
|
81
|
+
* @returns The `children`, rendered as-is, or called with the boundary's {@link QueryErrorResetBoundaryValue}
|
|
82
|
+
* if `children` is a function.
|
|
83
|
+
*
|
|
84
|
+
* @example
|
|
85
|
+
* ```tsx
|
|
86
|
+
* import { useErrorBoundary } from 'preact/hooks'
|
|
87
|
+
* import type { ComponentChildren } from 'preact'
|
|
88
|
+
* import { QueryErrorResetBoundary } from '@tanstack/preact-query'
|
|
89
|
+
*
|
|
90
|
+
* function ErrorBoundary({
|
|
91
|
+
* children,
|
|
92
|
+
* reset,
|
|
93
|
+
* }: {
|
|
94
|
+
* children: ComponentChildren
|
|
95
|
+
* reset: () => void
|
|
96
|
+
* }) {
|
|
97
|
+
* const [error, resetError] = useErrorBoundary(() => reset())
|
|
98
|
+
*
|
|
99
|
+
* if (error) {
|
|
100
|
+
* return (
|
|
101
|
+
* <div>
|
|
102
|
+
* There was an error!
|
|
103
|
+
* <button onClick={() => resetError()}>Try again</button>
|
|
104
|
+
* </div>
|
|
105
|
+
* )
|
|
106
|
+
* }
|
|
107
|
+
*
|
|
108
|
+
* return children
|
|
109
|
+
* }
|
|
110
|
+
*
|
|
111
|
+
* const App = () => (
|
|
112
|
+
* <QueryErrorResetBoundary>
|
|
113
|
+
* {({ reset }) => (
|
|
114
|
+
* <ErrorBoundary reset={reset}>
|
|
115
|
+
* <Page />
|
|
116
|
+
* </ErrorBoundary>
|
|
117
|
+
* )}
|
|
118
|
+
* </QueryErrorResetBoundary>
|
|
119
|
+
* )
|
|
120
|
+
* ```
|
|
121
|
+
*/
|
|
16
122
|
declare const QueryErrorResetBoundary: ({ children }: QueryErrorResetBoundaryProps) => import("preact").JSX.Element;
|
|
17
123
|
//#endregion
|
|
18
124
|
export { QueryErrorClearResetFunction, QueryErrorIsResetFunction, QueryErrorResetBoundary, QueryErrorResetBoundaryFunction, QueryErrorResetBoundaryProps, QueryErrorResetBoundaryValue, QueryErrorResetFunction, useQueryErrorResetBoundary };
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"QueryErrorResetBoundary.d.cts","names":[],"sources":["../../src/QueryErrorResetBoundary.tsx"],"mappings":"
|
|
1
|
+
{"version":3,"file":"QueryErrorResetBoundary.d.cts","names":[],"sources":["../../src/QueryErrorResetBoundary.tsx"],"mappings":";;;;;KASY;;;;KAKA;;;;KAKA;UAEK;;;;EAIf,YAAY;;;;EAIZ,SAAS;;;;EAIT,OAAO;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;cAmDI,kCAA0B;;;;;;;KAW3B,mCACV,OAAO,iCACJ;;;;UAKY;;;;;EAKf,UAAU,kCAAkC;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;cAiDjC,4BAA2B,YAErC,kDAA4B,IAAA"}
|
|
@@ -1,18 +1,124 @@
|
|
|
1
1
|
import { ComponentChildren } from "preact";
|
|
2
2
|
//#region src/QueryErrorResetBoundary.d.ts
|
|
3
|
+
/**
|
|
4
|
+
* Resets any query errors within the boundary, so queries know they can try again.
|
|
5
|
+
*/
|
|
3
6
|
type QueryErrorResetFunction = () => void;
|
|
7
|
+
/**
|
|
8
|
+
* Returns whether the boundary has been reset and not yet cleared.
|
|
9
|
+
*/
|
|
4
10
|
type QueryErrorIsResetFunction = () => boolean;
|
|
11
|
+
/**
|
|
12
|
+
* Clears the reset state, so queries know not to try again until the boundary is reset again.
|
|
13
|
+
*/
|
|
5
14
|
type QueryErrorClearResetFunction = () => void;
|
|
6
15
|
interface QueryErrorResetBoundaryValue {
|
|
16
|
+
/**
|
|
17
|
+
* Clears the reset state, so queries know not to try again until the boundary is reset again.
|
|
18
|
+
*/
|
|
7
19
|
clearReset: QueryErrorClearResetFunction;
|
|
20
|
+
/**
|
|
21
|
+
* Returns whether the boundary has been reset and not yet cleared.
|
|
22
|
+
*/
|
|
8
23
|
isReset: QueryErrorIsResetFunction;
|
|
24
|
+
/**
|
|
25
|
+
* Resets any query errors within the boundary, so queries know they can try again.
|
|
26
|
+
*/
|
|
9
27
|
reset: QueryErrorResetFunction;
|
|
10
28
|
}
|
|
29
|
+
/**
|
|
30
|
+
* This hook will reset any query errors within the closest `QueryErrorResetBoundary`. If there is no boundary
|
|
31
|
+
* defined it will reset them globally.
|
|
32
|
+
*
|
|
33
|
+
* @returns The boundary's {@link QueryErrorResetBoundaryValue}.
|
|
34
|
+
*
|
|
35
|
+
* @example
|
|
36
|
+
* ```tsx
|
|
37
|
+
* import { useErrorBoundary } from 'preact/hooks'
|
|
38
|
+
* import type { ComponentChildren } from 'preact'
|
|
39
|
+
* import { useQueryErrorResetBoundary } from '@tanstack/preact-query'
|
|
40
|
+
*
|
|
41
|
+
* function App({ children }: { children: ComponentChildren }) {
|
|
42
|
+
* const { reset } = useQueryErrorResetBoundary()
|
|
43
|
+
* const [error, resetError] = useErrorBoundary(() => reset())
|
|
44
|
+
*
|
|
45
|
+
* if (error) {
|
|
46
|
+
* return (
|
|
47
|
+
* <div>
|
|
48
|
+
* There was an error!
|
|
49
|
+
* <button onClick={() => resetError()}>Try again</button>
|
|
50
|
+
* </div>
|
|
51
|
+
* )
|
|
52
|
+
* }
|
|
53
|
+
*
|
|
54
|
+
* return children
|
|
55
|
+
* }
|
|
56
|
+
* ```
|
|
57
|
+
*/
|
|
11
58
|
declare const useQueryErrorResetBoundary: () => QueryErrorResetBoundaryValue;
|
|
59
|
+
/**
|
|
60
|
+
* A render-prop function usable as `children` on `QueryErrorResetBoundary`.
|
|
61
|
+
*
|
|
62
|
+
* @param value - The boundary's {@link QueryErrorResetBoundaryValue}.
|
|
63
|
+
* @returns The children to render.
|
|
64
|
+
*/
|
|
12
65
|
type QueryErrorResetBoundaryFunction = (value: QueryErrorResetBoundaryValue) => ComponentChildren;
|
|
66
|
+
/**
|
|
67
|
+
* The props accepted by `QueryErrorResetBoundary`.
|
|
68
|
+
*/
|
|
13
69
|
interface QueryErrorResetBoundaryProps {
|
|
70
|
+
/**
|
|
71
|
+
* Either a plain node, or a function that receives the boundary's {@link QueryErrorResetBoundaryValue} and
|
|
72
|
+
* returns a node.
|
|
73
|
+
*/
|
|
14
74
|
children: QueryErrorResetBoundaryFunction | ComponentChildren;
|
|
15
75
|
}
|
|
76
|
+
/**
|
|
77
|
+
* When using `suspense` or `throwOnError` in your queries, you need a way to let queries know that you want to
|
|
78
|
+
* try again when re-rendering after some error occurred. With the `QueryErrorResetBoundary` component you can
|
|
79
|
+
* reset any query errors within the boundaries of the component.
|
|
80
|
+
*
|
|
81
|
+
* @returns The `children`, rendered as-is, or called with the boundary's {@link QueryErrorResetBoundaryValue}
|
|
82
|
+
* if `children` is a function.
|
|
83
|
+
*
|
|
84
|
+
* @example
|
|
85
|
+
* ```tsx
|
|
86
|
+
* import { useErrorBoundary } from 'preact/hooks'
|
|
87
|
+
* import type { ComponentChildren } from 'preact'
|
|
88
|
+
* import { QueryErrorResetBoundary } from '@tanstack/preact-query'
|
|
89
|
+
*
|
|
90
|
+
* function ErrorBoundary({
|
|
91
|
+
* children,
|
|
92
|
+
* reset,
|
|
93
|
+
* }: {
|
|
94
|
+
* children: ComponentChildren
|
|
95
|
+
* reset: () => void
|
|
96
|
+
* }) {
|
|
97
|
+
* const [error, resetError] = useErrorBoundary(() => reset())
|
|
98
|
+
*
|
|
99
|
+
* if (error) {
|
|
100
|
+
* return (
|
|
101
|
+
* <div>
|
|
102
|
+
* There was an error!
|
|
103
|
+
* <button onClick={() => resetError()}>Try again</button>
|
|
104
|
+
* </div>
|
|
105
|
+
* )
|
|
106
|
+
* }
|
|
107
|
+
*
|
|
108
|
+
* return children
|
|
109
|
+
* }
|
|
110
|
+
*
|
|
111
|
+
* const App = () => (
|
|
112
|
+
* <QueryErrorResetBoundary>
|
|
113
|
+
* {({ reset }) => (
|
|
114
|
+
* <ErrorBoundary reset={reset}>
|
|
115
|
+
* <Page />
|
|
116
|
+
* </ErrorBoundary>
|
|
117
|
+
* )}
|
|
118
|
+
* </QueryErrorResetBoundary>
|
|
119
|
+
* )
|
|
120
|
+
* ```
|
|
121
|
+
*/
|
|
16
122
|
declare const QueryErrorResetBoundary: ({ children }: QueryErrorResetBoundaryProps) => import("preact").JSX.Element;
|
|
17
123
|
//#endregion
|
|
18
124
|
export { QueryErrorClearResetFunction, QueryErrorIsResetFunction, QueryErrorResetBoundary, QueryErrorResetBoundaryFunction, QueryErrorResetBoundaryProps, QueryErrorResetBoundaryValue, QueryErrorResetFunction, useQueryErrorResetBoundary };
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"QueryErrorResetBoundary.d.ts","names":[],"sources":["../../src/QueryErrorResetBoundary.tsx"],"mappings":"
|
|
1
|
+
{"version":3,"file":"QueryErrorResetBoundary.d.ts","names":[],"sources":["../../src/QueryErrorResetBoundary.tsx"],"mappings":";;;;;KASY;;;;KAKA;;;;KAKA;UAEK;;;;EAIf,YAAY;;;;EAIZ,SAAS;;;;EAIT,OAAO;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;cAmDI,kCAA0B;;;;;;;KAW3B,mCACV,OAAO,iCACJ;;;;UAKY;;;;;EAKf,UAAU,kCAAkC;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;cAiDjC,4BAA2B,YAErC,kDAA4B,IAAA"}
|
|
@@ -17,7 +17,82 @@ function createValue() {
|
|
|
17
17
|
};
|
|
18
18
|
}
|
|
19
19
|
const QueryErrorResetBoundaryContext = createContext(createValue());
|
|
20
|
+
/**
|
|
21
|
+
* This hook will reset any query errors within the closest `QueryErrorResetBoundary`. If there is no boundary
|
|
22
|
+
* defined it will reset them globally.
|
|
23
|
+
*
|
|
24
|
+
* @returns The boundary's {@link QueryErrorResetBoundaryValue}.
|
|
25
|
+
*
|
|
26
|
+
* @example
|
|
27
|
+
* ```tsx
|
|
28
|
+
* import { useErrorBoundary } from 'preact/hooks'
|
|
29
|
+
* import type { ComponentChildren } from 'preact'
|
|
30
|
+
* import { useQueryErrorResetBoundary } from '@tanstack/preact-query'
|
|
31
|
+
*
|
|
32
|
+
* function App({ children }: { children: ComponentChildren }) {
|
|
33
|
+
* const { reset } = useQueryErrorResetBoundary()
|
|
34
|
+
* const [error, resetError] = useErrorBoundary(() => reset())
|
|
35
|
+
*
|
|
36
|
+
* if (error) {
|
|
37
|
+
* return (
|
|
38
|
+
* <div>
|
|
39
|
+
* There was an error!
|
|
40
|
+
* <button onClick={() => resetError()}>Try again</button>
|
|
41
|
+
* </div>
|
|
42
|
+
* )
|
|
43
|
+
* }
|
|
44
|
+
*
|
|
45
|
+
* return children
|
|
46
|
+
* }
|
|
47
|
+
* ```
|
|
48
|
+
*/
|
|
20
49
|
const useQueryErrorResetBoundary = () => useContext(QueryErrorResetBoundaryContext);
|
|
50
|
+
/**
|
|
51
|
+
* When using `suspense` or `throwOnError` in your queries, you need a way to let queries know that you want to
|
|
52
|
+
* try again when re-rendering after some error occurred. With the `QueryErrorResetBoundary` component you can
|
|
53
|
+
* reset any query errors within the boundaries of the component.
|
|
54
|
+
*
|
|
55
|
+
* @returns The `children`, rendered as-is, or called with the boundary's {@link QueryErrorResetBoundaryValue}
|
|
56
|
+
* if `children` is a function.
|
|
57
|
+
*
|
|
58
|
+
* @example
|
|
59
|
+
* ```tsx
|
|
60
|
+
* import { useErrorBoundary } from 'preact/hooks'
|
|
61
|
+
* import type { ComponentChildren } from 'preact'
|
|
62
|
+
* import { QueryErrorResetBoundary } from '@tanstack/preact-query'
|
|
63
|
+
*
|
|
64
|
+
* function ErrorBoundary({
|
|
65
|
+
* children,
|
|
66
|
+
* reset,
|
|
67
|
+
* }: {
|
|
68
|
+
* children: ComponentChildren
|
|
69
|
+
* reset: () => void
|
|
70
|
+
* }) {
|
|
71
|
+
* const [error, resetError] = useErrorBoundary(() => reset())
|
|
72
|
+
*
|
|
73
|
+
* if (error) {
|
|
74
|
+
* return (
|
|
75
|
+
* <div>
|
|
76
|
+
* There was an error!
|
|
77
|
+
* <button onClick={() => resetError()}>Try again</button>
|
|
78
|
+
* </div>
|
|
79
|
+
* )
|
|
80
|
+
* }
|
|
81
|
+
*
|
|
82
|
+
* return children
|
|
83
|
+
* }
|
|
84
|
+
*
|
|
85
|
+
* const App = () => (
|
|
86
|
+
* <QueryErrorResetBoundary>
|
|
87
|
+
* {({ reset }) => (
|
|
88
|
+
* <ErrorBoundary reset={reset}>
|
|
89
|
+
* <Page />
|
|
90
|
+
* </ErrorBoundary>
|
|
91
|
+
* )}
|
|
92
|
+
* </QueryErrorResetBoundary>
|
|
93
|
+
* )
|
|
94
|
+
* ```
|
|
95
|
+
*/
|
|
21
96
|
const QueryErrorResetBoundary = ({ children }) => {
|
|
22
97
|
const [value] = useState(() => createValue());
|
|
23
98
|
return /* @__PURE__ */ jsx(QueryErrorResetBoundaryContext.Provider, {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"QueryErrorResetBoundary.js","names":[],"sources":["../../src/QueryErrorResetBoundary.tsx"],"sourcesContent":["import { createContext } from 'preact'\nimport type { ComponentChildren } from 'preact'\nimport { useContext, useState } from 'preact/hooks'\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 = createContext(createValue())\n\n// HOOK\n\nexport const useQueryErrorResetBoundary = () =>\n useContext(QueryErrorResetBoundaryContext)\n\n// COMPONENT\n\nexport type QueryErrorResetBoundaryFunction = (\n value: QueryErrorResetBoundaryValue,\n) => ComponentChildren\n\nexport interface QueryErrorResetBoundaryProps {\n children: QueryErrorResetBoundaryFunction | ComponentChildren\n}\n\nexport const QueryErrorResetBoundary = ({\n children,\n}: QueryErrorResetBoundaryProps) => {\n const [value] = 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":["import { createContext } from 'preact'\nimport type { ComponentChildren } from 'preact'\nimport { useContext, useState } from 'preact/hooks'\n\n// CONTEXT\n\n/**\n * Resets any query errors within the boundary, so queries know they can try again.\n */\nexport type QueryErrorResetFunction = () => void\n\n/**\n * Returns whether the boundary has been reset and not yet cleared.\n */\nexport type QueryErrorIsResetFunction = () => boolean\n\n/**\n * Clears the reset state, so queries know not to try again until the boundary is reset again.\n */\nexport type QueryErrorClearResetFunction = () => void\n\nexport interface QueryErrorResetBoundaryValue {\n /**\n * Clears the reset state, so queries know not to try again until the boundary is reset again.\n */\n clearReset: QueryErrorClearResetFunction\n /**\n * Returns whether the boundary has been reset and not yet cleared.\n */\n isReset: QueryErrorIsResetFunction\n /**\n * Resets any query errors within the boundary, so queries know they can try again.\n */\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 = 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 { useErrorBoundary } from 'preact/hooks'\n * import type { ComponentChildren } from 'preact'\n * import { useQueryErrorResetBoundary } from '@tanstack/preact-query'\n *\n * function App({ children }: { children: ComponentChildren }) {\n * const { reset } = useQueryErrorResetBoundary()\n * const [error, resetError] = useErrorBoundary(() => reset())\n *\n * if (error) {\n * return (\n * <div>\n * There was an error!\n * <button onClick={() => resetError()}>Try again</button>\n * </div>\n * )\n * }\n *\n * return children\n * }\n * ```\n */\nexport const useQueryErrorResetBoundary = () =>\n 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) => ComponentChildren\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 | ComponentChildren\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 { useErrorBoundary } from 'preact/hooks'\n * import type { ComponentChildren } from 'preact'\n * import { QueryErrorResetBoundary } from '@tanstack/preact-query'\n *\n * function ErrorBoundary({\n * children,\n * reset,\n * }: {\n * children: ComponentChildren\n * reset: () => void\n * }) {\n * const [error, resetError] = useErrorBoundary(() => reset())\n *\n * if (error) {\n * return (\n * <div>\n * There was an error!\n * <button onClick={() => resetError()}>Try again</button>\n * </div>\n * )\n * }\n *\n * return children\n * }\n *\n * const App = () => (\n * <QueryErrorResetBoundary>\n * {({ reset }) => (\n * <ErrorBoundary reset={reset}>\n * <Page />\n * </ErrorBoundary>\n * )}\n * </QueryErrorResetBoundary>\n * )\n * ```\n */\nexport const QueryErrorResetBoundary = ({\n children,\n}: QueryErrorResetBoundaryProps) => {\n const [value] = useState(() => createValue())\n return (\n <QueryErrorResetBoundaryContext.Provider value={value}>\n {typeof children === 'function' ? children(value) : children}\n </QueryErrorResetBoundaryContext.Provider>\n )\n}\n"],"mappings":";;;;AAoCA,SAAS,cAA4C;CACnD,IAAI,UAAU;CACd,OAAO;EACL,kBAAkB;GAChB,UAAU;EACZ;EACA,aAAa;GACX,UAAU;EACZ;EACA,eAAe;GACb,OAAO;EACT;CACF;AACF;AAEA,MAAM,iCAAiC,cAAc,YAAY,CAAC;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAiClE,MAAa,mCACX,WAAW,8BAA8B;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAuE3C,MAAa,2BAA2B,EACtC,eACkC;CAClC,MAAM,CAAC,SAAS,eAAe,YAAY,CAAC;CAC5C,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'\n\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":";;AAgJA,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'\n\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, omit `queryFn` or use a default query function instead.\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 *\n * @example\n * ```tsx\n * import { infiniteQueryOptions, useInfiniteQuery } from '@tanstack/preact-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 * const { data } = useInfiniteQuery(projectsOptions)\n * return <>{data.pages.map((page) => page.projects.map((p) => <p key={p.id}>{p.name}</p>))}</>\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 *\n * @example\n * ```tsx\n * import { infiniteQueryOptions } from '@tanstack/preact-query'\n *\n * export const projectsOptions = infiniteQueryOptions({\n * queryKey: ['projects'],\n * queryFn: ({ pageParam }) => fetchProjects(pageParam),\n * initialPageParam: 0,\n * getNextPageParam: (lastPage) => lastPage.nextId,\n * })\n * ```\n *\n * @example\n * A parameterized factory, reused across a hook and an imperative call with the same cache entry:\n * ```tsx\n * import {\n * infiniteQueryOptions,\n * noop,\n * useInfiniteQuery,\n * } from '@tanstack/preact-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 result = useInfiniteQuery(commentsOptions(postId))\n * if (!result.isSuccess) return 'Loading...'\n * return (\n * <>\n * {result.data.pages.map((page) => page.comments.map((c) => <p key={c.id}>{c.text}</p>))}\n * </>\n * )\n * }\n *\n * // Elsewhere, e.g. to warm the cache before rendering `<Comments>`:\n * queryClient.infiniteQuery(commentsOptions(postId)).catch(noop)\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 *\n * @example\n * ```tsx\n * import { infiniteQueryOptions } from '@tanstack/preact-query'\n *\n * export const projectsOptions = infiniteQueryOptions({\n * queryKey: ['projects'],\n * queryFn: ({ pageParam }) => fetchProjects(pageParam),\n * initialPageParam: 0,\n * getNextPageParam: (lastPage) => lastPage.nextId,\n * })\n * ```\n *\n * @example\n * A parameterized factory, reused across a hook and an imperative call with the same cache entry:\n * ```tsx\n * import {\n * infiniteQueryOptions,\n * noop,\n * useInfiniteQuery,\n * } from '@tanstack/preact-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 result = useInfiniteQuery(commentsOptions(postId))\n * if (!result.isSuccess) return 'Loading...'\n * return (\n * <>\n * {result.data.pages.map((page) => page.comments.map((c) => <p key={c.id}>{c.text}</p>))}\n * </>\n * )\n * }\n *\n * // Elsewhere, e.g. to warm the cache before rendering `<Comments>`:\n * queryClient.infiniteQuery(commentsOptions(postId)).catch(noop)\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":";;AA2UA,SAAgB,qBAAqB,SAAkB;CACrD,OAAO;AACT"}
|