@tanstack/react-query 5.104.0 → 5.104.2
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 +2 -3
- package/build/legacy/HydrationBoundary.cjs.map +1 -1
- package/build/legacy/HydrationBoundary.d.cts +2 -3
- package/build/legacy/HydrationBoundary.d.cts.map +1 -1
- package/build/legacy/HydrationBoundary.d.ts +2 -3
- package/build/legacy/HydrationBoundary.d.ts.map +1 -1
- package/build/legacy/HydrationBoundary.js +2 -3
- package/build/legacy/HydrationBoundary.js.map +1 -1
- package/build/legacy/IsRestoringProvider.cjs +0 -1
- package/build/legacy/IsRestoringProvider.cjs.map +1 -1
- package/build/legacy/IsRestoringProvider.d.cts +0 -1
- package/build/legacy/IsRestoringProvider.d.cts.map +1 -1
- package/build/legacy/IsRestoringProvider.d.ts +0 -1
- package/build/legacy/IsRestoringProvider.d.ts.map +1 -1
- package/build/legacy/IsRestoringProvider.js +0 -1
- package/build/legacy/IsRestoringProvider.js.map +1 -1
- package/build/legacy/QueryClientProvider.cjs +3 -4
- package/build/legacy/QueryClientProvider.cjs.map +1 -1
- package/build/legacy/QueryClientProvider.d.cts +3 -4
- package/build/legacy/QueryClientProvider.d.cts.map +1 -1
- package/build/legacy/QueryClientProvider.d.ts +3 -4
- package/build/legacy/QueryClientProvider.d.ts.map +1 -1
- package/build/legacy/QueryClientProvider.js +3 -4
- package/build/legacy/QueryClientProvider.js.map +1 -1
- package/build/legacy/QueryErrorResetBoundary.cjs +5 -5
- package/build/legacy/QueryErrorResetBoundary.cjs.map +1 -1
- package/build/legacy/QueryErrorResetBoundary.d.cts +23 -5
- package/build/legacy/QueryErrorResetBoundary.d.cts.map +1 -1
- package/build/legacy/QueryErrorResetBoundary.d.ts +23 -5
- package/build/legacy/QueryErrorResetBoundary.d.ts.map +1 -1
- package/build/legacy/QueryErrorResetBoundary.js +5 -5
- package/build/legacy/QueryErrorResetBoundary.js.map +1 -1
- package/build/legacy/errorBoundaryUtils.cjs +21 -0
- package/build/legacy/errorBoundaryUtils.cjs.map +1 -1
- package/build/legacy/errorBoundaryUtils.d.cts +21 -0
- package/build/legacy/errorBoundaryUtils.d.cts.map +1 -1
- package/build/legacy/errorBoundaryUtils.d.ts +21 -0
- package/build/legacy/errorBoundaryUtils.d.ts.map +1 -1
- package/build/legacy/errorBoundaryUtils.js +21 -0
- package/build/legacy/errorBoundaryUtils.js.map +1 -1
- package/build/legacy/infiniteQueryOptions.cjs.map +1 -1
- package/build/legacy/infiniteQueryOptions.d.cts +5 -16
- package/build/legacy/infiniteQueryOptions.d.cts.map +1 -1
- package/build/legacy/infiniteQueryOptions.d.ts +5 -16
- 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 +2 -6
- package/build/legacy/mutationOptions.d.cts.map +1 -1
- package/build/legacy/mutationOptions.d.ts +2 -6
- 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 +6 -16
- package/build/legacy/queryOptions.d.cts.map +1 -1
- package/build/legacy/queryOptions.d.ts +6 -16
- package/build/legacy/queryOptions.d.ts.map +1 -1
- package/build/legacy/queryOptions.js.map +1 -1
- package/build/legacy/suspense.cjs +27 -0
- package/build/legacy/suspense.cjs.map +1 -1
- package/build/legacy/suspense.d.cts +27 -0
- package/build/legacy/suspense.d.cts.map +1 -1
- package/build/legacy/suspense.d.ts +27 -0
- package/build/legacy/suspense.d.ts.map +1 -1
- package/build/legacy/suspense.js +27 -0
- package/build/legacy/suspense.js.map +1 -1
- package/build/legacy/types.cjs.map +1 -1
- package/build/legacy/types.d.cts +2 -22
- package/build/legacy/types.d.cts.map +1 -1
- package/build/legacy/types.d.ts +2 -22
- package/build/legacy/types.d.ts.map +1 -1
- package/build/legacy/types.js.map +1 -1
- package/build/legacy/useBaseQuery.cjs +13 -0
- package/build/legacy/useBaseQuery.cjs.map +1 -1
- package/build/legacy/useBaseQuery.d.cts +13 -0
- package/build/legacy/useBaseQuery.d.cts.map +1 -1
- package/build/legacy/useBaseQuery.d.ts +13 -0
- package/build/legacy/useBaseQuery.d.ts.map +1 -1
- package/build/legacy/useBaseQuery.js +13 -0
- package/build/legacy/useBaseQuery.js.map +1 -1
- package/build/legacy/useInfiniteQuery.cjs.map +1 -1
- package/build/legacy/useInfiniteQuery.d.cts +12 -21
- package/build/legacy/useInfiniteQuery.d.cts.map +1 -1
- package/build/legacy/useInfiniteQuery.d.ts +12 -21
- package/build/legacy/useInfiniteQuery.d.ts.map +1 -1
- package/build/legacy/useInfiniteQuery.js.map +1 -1
- package/build/legacy/useIsFetching.cjs +0 -3
- package/build/legacy/useIsFetching.cjs.map +1 -1
- package/build/legacy/useIsFetching.d.cts +0 -3
- package/build/legacy/useIsFetching.d.cts.map +1 -1
- package/build/legacy/useIsFetching.d.ts +0 -3
- package/build/legacy/useIsFetching.d.ts.map +1 -1
- package/build/legacy/useIsFetching.js +0 -3
- package/build/legacy/useIsFetching.js.map +1 -1
- package/build/legacy/useMutation.cjs +4 -8
- package/build/legacy/useMutation.cjs.map +1 -1
- package/build/legacy/useMutation.d.cts +4 -8
- package/build/legacy/useMutation.d.cts.map +1 -1
- package/build/legacy/useMutation.d.ts +4 -8
- package/build/legacy/useMutation.d.ts.map +1 -1
- package/build/legacy/useMutation.js +4 -8
- package/build/legacy/useMutation.js.map +1 -1
- package/build/legacy/useMutationState.cjs +13 -12
- package/build/legacy/useMutationState.cjs.map +1 -1
- package/build/legacy/useMutationState.d.cts +0 -6
- package/build/legacy/useMutationState.d.cts.map +1 -1
- package/build/legacy/useMutationState.d.ts +0 -6
- package/build/legacy/useMutationState.d.ts.map +1 -1
- package/build/legacy/useMutationState.js +13 -12
- package/build/legacy/useMutationState.js.map +1 -1
- package/build/legacy/usePrefetchInfiniteQuery.cjs +0 -3
- package/build/legacy/usePrefetchInfiniteQuery.cjs.map +1 -1
- package/build/legacy/usePrefetchInfiniteQuery.d.cts +0 -3
- package/build/legacy/usePrefetchInfiniteQuery.d.cts.map +1 -1
- package/build/legacy/usePrefetchInfiniteQuery.d.ts +0 -3
- package/build/legacy/usePrefetchInfiniteQuery.d.ts.map +1 -1
- package/build/legacy/usePrefetchInfiniteQuery.js +0 -3
- package/build/legacy/usePrefetchInfiniteQuery.js.map +1 -1
- package/build/legacy/usePrefetchQuery.cjs +0 -3
- package/build/legacy/usePrefetchQuery.cjs.map +1 -1
- package/build/legacy/usePrefetchQuery.d.cts +0 -3
- package/build/legacy/usePrefetchQuery.d.cts.map +1 -1
- package/build/legacy/usePrefetchQuery.d.ts +0 -3
- package/build/legacy/usePrefetchQuery.d.ts.map +1 -1
- package/build/legacy/usePrefetchQuery.js +0 -3
- package/build/legacy/usePrefetchQuery.js.map +1 -1
- package/build/legacy/useQueries.cjs +7 -8
- package/build/legacy/useQueries.cjs.map +1 -1
- package/build/legacy/useQueries.d.cts +7 -11
- package/build/legacy/useQueries.d.cts.map +1 -1
- package/build/legacy/useQueries.d.ts +7 -11
- package/build/legacy/useQueries.d.ts.map +1 -1
- package/build/legacy/useQueries.js +7 -8
- package/build/legacy/useQueries.js.map +1 -1
- package/build/legacy/useQuery.cjs.map +1 -1
- package/build/legacy/useQuery.d.cts +8 -13
- package/build/legacy/useQuery.d.cts.map +1 -1
- package/build/legacy/useQuery.d.ts +8 -13
- package/build/legacy/useQuery.d.ts.map +1 -1
- package/build/legacy/useQuery.js.map +1 -1
- package/build/legacy/useSuspenseInfiniteQuery.cjs +6 -8
- package/build/legacy/useSuspenseInfiniteQuery.cjs.map +1 -1
- package/build/legacy/useSuspenseInfiniteQuery.d.cts +6 -8
- package/build/legacy/useSuspenseInfiniteQuery.d.cts.map +1 -1
- package/build/legacy/useSuspenseInfiniteQuery.d.ts +6 -8
- package/build/legacy/useSuspenseInfiniteQuery.d.ts.map +1 -1
- package/build/legacy/useSuspenseInfiniteQuery.js +6 -8
- package/build/legacy/useSuspenseInfiniteQuery.js.map +1 -1
- package/build/legacy/useSuspenseQueries.cjs.map +1 -1
- package/build/legacy/useSuspenseQueries.d.cts +0 -9
- package/build/legacy/useSuspenseQueries.d.cts.map +1 -1
- package/build/legacy/useSuspenseQueries.d.ts +0 -9
- package/build/legacy/useSuspenseQueries.d.ts.map +1 -1
- package/build/legacy/useSuspenseQueries.js.map +1 -1
- package/build/legacy/useSuspenseQuery.cjs +4 -6
- package/build/legacy/useSuspenseQuery.cjs.map +1 -1
- package/build/legacy/useSuspenseQuery.d.cts +4 -6
- package/build/legacy/useSuspenseQuery.d.cts.map +1 -1
- package/build/legacy/useSuspenseQuery.d.ts +4 -6
- package/build/legacy/useSuspenseQuery.d.ts.map +1 -1
- package/build/legacy/useSuspenseQuery.js +4 -6
- package/build/legacy/useSuspenseQuery.js.map +1 -1
- package/build/modern/HydrationBoundary.cjs +2 -3
- package/build/modern/HydrationBoundary.cjs.map +1 -1
- package/build/modern/HydrationBoundary.d.cts +2 -3
- package/build/modern/HydrationBoundary.d.cts.map +1 -1
- package/build/modern/HydrationBoundary.d.ts +2 -3
- package/build/modern/HydrationBoundary.d.ts.map +1 -1
- package/build/modern/HydrationBoundary.js +2 -3
- package/build/modern/HydrationBoundary.js.map +1 -1
- package/build/modern/IsRestoringProvider.cjs +0 -1
- package/build/modern/IsRestoringProvider.cjs.map +1 -1
- package/build/modern/IsRestoringProvider.d.cts +0 -1
- package/build/modern/IsRestoringProvider.d.cts.map +1 -1
- package/build/modern/IsRestoringProvider.d.ts +0 -1
- package/build/modern/IsRestoringProvider.d.ts.map +1 -1
- package/build/modern/IsRestoringProvider.js +0 -1
- package/build/modern/IsRestoringProvider.js.map +1 -1
- package/build/modern/QueryClientProvider.cjs +3 -4
- package/build/modern/QueryClientProvider.cjs.map +1 -1
- package/build/modern/QueryClientProvider.d.cts +3 -4
- package/build/modern/QueryClientProvider.d.cts.map +1 -1
- package/build/modern/QueryClientProvider.d.ts +3 -4
- package/build/modern/QueryClientProvider.d.ts.map +1 -1
- package/build/modern/QueryClientProvider.js +3 -4
- package/build/modern/QueryClientProvider.js.map +1 -1
- package/build/modern/QueryErrorResetBoundary.cjs +5 -5
- package/build/modern/QueryErrorResetBoundary.cjs.map +1 -1
- package/build/modern/QueryErrorResetBoundary.d.cts +23 -5
- package/build/modern/QueryErrorResetBoundary.d.cts.map +1 -1
- package/build/modern/QueryErrorResetBoundary.d.ts +23 -5
- package/build/modern/QueryErrorResetBoundary.d.ts.map +1 -1
- package/build/modern/QueryErrorResetBoundary.js +5 -5
- package/build/modern/QueryErrorResetBoundary.js.map +1 -1
- package/build/modern/errorBoundaryUtils.cjs +21 -0
- package/build/modern/errorBoundaryUtils.cjs.map +1 -1
- package/build/modern/errorBoundaryUtils.d.cts +21 -0
- package/build/modern/errorBoundaryUtils.d.cts.map +1 -1
- package/build/modern/errorBoundaryUtils.d.ts +21 -0
- package/build/modern/errorBoundaryUtils.d.ts.map +1 -1
- package/build/modern/errorBoundaryUtils.js +21 -0
- package/build/modern/errorBoundaryUtils.js.map +1 -1
- package/build/modern/infiniteQueryOptions.cjs.map +1 -1
- package/build/modern/infiniteQueryOptions.d.cts +5 -16
- package/build/modern/infiniteQueryOptions.d.cts.map +1 -1
- package/build/modern/infiniteQueryOptions.d.ts +5 -16
- 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 +2 -6
- package/build/modern/mutationOptions.d.cts.map +1 -1
- package/build/modern/mutationOptions.d.ts +2 -6
- 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 +6 -16
- package/build/modern/queryOptions.d.cts.map +1 -1
- package/build/modern/queryOptions.d.ts +6 -16
- package/build/modern/queryOptions.d.ts.map +1 -1
- package/build/modern/queryOptions.js.map +1 -1
- package/build/modern/suspense.cjs +27 -0
- package/build/modern/suspense.cjs.map +1 -1
- package/build/modern/suspense.d.cts +27 -0
- package/build/modern/suspense.d.cts.map +1 -1
- package/build/modern/suspense.d.ts +27 -0
- package/build/modern/suspense.d.ts.map +1 -1
- package/build/modern/suspense.js +27 -0
- package/build/modern/suspense.js.map +1 -1
- package/build/modern/types.cjs.map +1 -1
- package/build/modern/types.d.cts +2 -22
- package/build/modern/types.d.cts.map +1 -1
- package/build/modern/types.d.ts +2 -22
- package/build/modern/types.d.ts.map +1 -1
- package/build/modern/types.js.map +1 -1
- package/build/modern/useBaseQuery.cjs +13 -0
- package/build/modern/useBaseQuery.cjs.map +1 -1
- package/build/modern/useBaseQuery.d.cts +13 -0
- package/build/modern/useBaseQuery.d.cts.map +1 -1
- package/build/modern/useBaseQuery.d.ts +13 -0
- package/build/modern/useBaseQuery.d.ts.map +1 -1
- package/build/modern/useBaseQuery.js +13 -0
- package/build/modern/useBaseQuery.js.map +1 -1
- package/build/modern/useInfiniteQuery.cjs.map +1 -1
- package/build/modern/useInfiniteQuery.d.cts +12 -21
- package/build/modern/useInfiniteQuery.d.cts.map +1 -1
- package/build/modern/useInfiniteQuery.d.ts +12 -21
- package/build/modern/useInfiniteQuery.d.ts.map +1 -1
- package/build/modern/useInfiniteQuery.js.map +1 -1
- package/build/modern/useIsFetching.cjs +0 -3
- package/build/modern/useIsFetching.cjs.map +1 -1
- package/build/modern/useIsFetching.d.cts +0 -3
- package/build/modern/useIsFetching.d.cts.map +1 -1
- package/build/modern/useIsFetching.d.ts +0 -3
- package/build/modern/useIsFetching.d.ts.map +1 -1
- package/build/modern/useIsFetching.js +0 -3
- package/build/modern/useIsFetching.js.map +1 -1
- package/build/modern/useMutation.cjs +4 -8
- package/build/modern/useMutation.cjs.map +1 -1
- package/build/modern/useMutation.d.cts +4 -8
- package/build/modern/useMutation.d.cts.map +1 -1
- package/build/modern/useMutation.d.ts +4 -8
- package/build/modern/useMutation.d.ts.map +1 -1
- package/build/modern/useMutation.js +4 -8
- package/build/modern/useMutation.js.map +1 -1
- package/build/modern/useMutationState.cjs +13 -12
- package/build/modern/useMutationState.cjs.map +1 -1
- package/build/modern/useMutationState.d.cts +0 -6
- package/build/modern/useMutationState.d.cts.map +1 -1
- package/build/modern/useMutationState.d.ts +0 -6
- package/build/modern/useMutationState.d.ts.map +1 -1
- package/build/modern/useMutationState.js +13 -12
- package/build/modern/useMutationState.js.map +1 -1
- package/build/modern/usePrefetchInfiniteQuery.cjs +0 -3
- package/build/modern/usePrefetchInfiniteQuery.cjs.map +1 -1
- package/build/modern/usePrefetchInfiniteQuery.d.cts +0 -3
- package/build/modern/usePrefetchInfiniteQuery.d.cts.map +1 -1
- package/build/modern/usePrefetchInfiniteQuery.d.ts +0 -3
- package/build/modern/usePrefetchInfiniteQuery.d.ts.map +1 -1
- package/build/modern/usePrefetchInfiniteQuery.js +0 -3
- package/build/modern/usePrefetchInfiniteQuery.js.map +1 -1
- package/build/modern/usePrefetchQuery.cjs +0 -3
- package/build/modern/usePrefetchQuery.cjs.map +1 -1
- package/build/modern/usePrefetchQuery.d.cts +0 -3
- package/build/modern/usePrefetchQuery.d.cts.map +1 -1
- package/build/modern/usePrefetchQuery.d.ts +0 -3
- package/build/modern/usePrefetchQuery.d.ts.map +1 -1
- package/build/modern/usePrefetchQuery.js +0 -3
- package/build/modern/usePrefetchQuery.js.map +1 -1
- package/build/modern/useQueries.cjs +7 -8
- package/build/modern/useQueries.cjs.map +1 -1
- package/build/modern/useQueries.d.cts +7 -11
- package/build/modern/useQueries.d.cts.map +1 -1
- package/build/modern/useQueries.d.ts +7 -11
- package/build/modern/useQueries.d.ts.map +1 -1
- package/build/modern/useQueries.js +7 -8
- package/build/modern/useQueries.js.map +1 -1
- package/build/modern/useQuery.cjs.map +1 -1
- package/build/modern/useQuery.d.cts +8 -13
- package/build/modern/useQuery.d.cts.map +1 -1
- package/build/modern/useQuery.d.ts +8 -13
- package/build/modern/useQuery.d.ts.map +1 -1
- package/build/modern/useQuery.js.map +1 -1
- package/build/modern/useSuspenseInfiniteQuery.cjs +6 -8
- package/build/modern/useSuspenseInfiniteQuery.cjs.map +1 -1
- package/build/modern/useSuspenseInfiniteQuery.d.cts +6 -8
- package/build/modern/useSuspenseInfiniteQuery.d.cts.map +1 -1
- package/build/modern/useSuspenseInfiniteQuery.d.ts +6 -8
- package/build/modern/useSuspenseInfiniteQuery.d.ts.map +1 -1
- package/build/modern/useSuspenseInfiniteQuery.js +6 -8
- package/build/modern/useSuspenseInfiniteQuery.js.map +1 -1
- package/build/modern/useSuspenseQueries.cjs.map +1 -1
- package/build/modern/useSuspenseQueries.d.cts +0 -9
- package/build/modern/useSuspenseQueries.d.cts.map +1 -1
- package/build/modern/useSuspenseQueries.d.ts +0 -9
- package/build/modern/useSuspenseQueries.d.ts.map +1 -1
- package/build/modern/useSuspenseQueries.js.map +1 -1
- package/build/modern/useSuspenseQuery.cjs +4 -6
- package/build/modern/useSuspenseQuery.cjs.map +1 -1
- package/build/modern/useSuspenseQuery.d.cts +4 -6
- package/build/modern/useSuspenseQuery.d.cts.map +1 -1
- package/build/modern/useSuspenseQuery.d.ts +4 -6
- package/build/modern/useSuspenseQuery.d.ts.map +1 -1
- package/build/modern/useSuspenseQuery.js +4 -6
- package/build/modern/useSuspenseQuery.js.map +1 -1
- package/package.json +10 -8
- package/src/HydrationBoundary.tsx +4 -5
- package/src/IsRestoringProvider.ts +0 -1
- package/src/QueryClientProvider.tsx +3 -4
- package/src/QueryErrorResetBoundary.tsx +30 -6
- package/src/errorBoundaryUtils.ts +21 -0
- package/src/infiniteQueryOptions.ts +5 -16
- package/src/mutationOptions.ts +2 -6
- package/src/queryOptions.ts +8 -17
- package/src/suspense.ts +29 -1
- package/src/types.ts +2 -22
- package/src/useBaseQuery.ts +13 -0
- package/src/useInfiniteQuery.ts +12 -21
- package/src/useIsFetching.ts +0 -3
- package/src/useMutation.ts +4 -8
- package/src/useMutationState.ts +15 -14
- package/src/usePrefetchInfiniteQuery.tsx +0 -3
- package/src/usePrefetchQuery.tsx +0 -3
- package/src/useQueries.ts +7 -11
- package/src/useQuery.ts +8 -13
- package/src/useSuspenseInfiniteQuery.ts +6 -8
- package/src/useSuspenseQueries.ts +0 -9
- package/src/useSuspenseQuery.ts +4 -6
package/src/types.ts
CHANGED
|
@@ -35,7 +35,6 @@ export type AnyUseBaseQueryOptions = UseBaseQueryOptions<
|
|
|
35
35
|
/**
|
|
36
36
|
* The options shared by `useQuery` and `useSuspenseQuery`. Extends {@link QueryObserverOptions} from
|
|
37
37
|
* `@tanstack/query-core` with the `react-query`-specific `subscribed` option.
|
|
38
|
-
*
|
|
39
38
|
* @template TQueryFnData - The type your `queryFn` resolves to.
|
|
40
39
|
* @template TError - The type of errors your `queryFn` may throw.
|
|
41
40
|
* @template TData - The type `data` ends up as after `select` runs. Defaults to `TQueryFnData` when no
|
|
@@ -59,7 +58,6 @@ export interface UseBaseQueryOptions<
|
|
|
59
58
|
> {
|
|
60
59
|
/**
|
|
61
60
|
* Set this to `false` to unsubscribe this observer from updates to the query cache.
|
|
62
|
-
*
|
|
63
61
|
* @defaultValue true
|
|
64
62
|
*/
|
|
65
63
|
subscribed?: boolean
|
|
@@ -68,7 +66,6 @@ export interface UseBaseQueryOptions<
|
|
|
68
66
|
/**
|
|
69
67
|
* The options accepted by `usePrefetchQuery` — everything you can pass to `queryClient.query`, except `queryFn`
|
|
70
68
|
* is required unless a default query function has been defined.
|
|
71
|
-
*
|
|
72
69
|
* @template TQueryFnData - The type your `queryFn` resolves to.
|
|
73
70
|
* @template TError - The type of errors your `queryFn` may throw.
|
|
74
71
|
* @template TData - The type `data` ends up as after `select` runs. Defaults to `TQueryFnData` when no
|
|
@@ -106,7 +103,6 @@ export type UsePrefetchQueryOptions<
|
|
|
106
103
|
/**
|
|
107
104
|
* The options accepted by `usePrefetchInfiniteQuery` — everything you can pass to `queryClient.infiniteQuery`,
|
|
108
105
|
* except `queryFn` is required unless a default query function has been defined.
|
|
109
|
-
*
|
|
110
106
|
* @template TQueryFnData - The type of a single page, as your `queryFn` resolves it.
|
|
111
107
|
* @template TError - The type of errors your `queryFn` may throw.
|
|
112
108
|
* @template TData - The type `data` ends up as after `select` runs. Defaults to `InfiniteData<TQueryFnData>`,
|
|
@@ -155,7 +151,6 @@ export type AnyUseQueryOptions = UseQueryOptions<any, any, any, any>
|
|
|
155
151
|
/**
|
|
156
152
|
* The options accepted by `useQuery`. Same as {@link UseBaseQueryOptions}, minus `suspense` (which
|
|
157
153
|
* `react-query` derives from which hook you call rather than exposing as an option).
|
|
158
|
-
*
|
|
159
154
|
* @template TQueryFnData - The type your `queryFn` resolves to.
|
|
160
155
|
* @template TError - The type of errors your `queryFn` may throw.
|
|
161
156
|
* @template TData - The type `data` ends up as after `select` runs. Defaults to `TQueryFnData` when no
|
|
@@ -186,7 +181,6 @@ export type AnyUseSuspenseQueryOptions = UseSuspenseQueryOptions<
|
|
|
186
181
|
* The options accepted by `useSuspenseQuery`. Same as {@link UseQueryOptions}, minus `enabled`, `throwOnError`,
|
|
187
182
|
* and `placeholderData` — Suspense hooks cannot render a "disabled" or "placeholder" state, so those options
|
|
188
183
|
* don't apply.
|
|
189
|
-
*
|
|
190
184
|
* @template TQueryFnData - The type your `queryFn` resolves to.
|
|
191
185
|
* @template TError - The type of errors your `queryFn` may throw.
|
|
192
186
|
* @template TData - The type `data` ends up as after `select` runs. Defaults to `TQueryFnData` when no
|
|
@@ -227,7 +221,6 @@ export type AnyUseInfiniteQueryOptions = UseInfiniteQueryOptions<
|
|
|
227
221
|
* The options accepted by `useInfiniteQuery`. Extends {@link InfiniteQueryObserverOptions} from
|
|
228
222
|
* `@tanstack/query-core` with the `react-query`-specific `subscribed` option, minus `suspense` (which
|
|
229
223
|
* `react-query` derives from which hook you call rather than exposing as an option).
|
|
230
|
-
*
|
|
231
224
|
* @template TQueryFnData - The type of a single page, as your `queryFn` resolves it.
|
|
232
225
|
* @template TError - The type of errors your `queryFn` may throw.
|
|
233
226
|
* @template TData - The type `data` ends up as after `select` runs — defaults to `InfiniteData<TQueryFnData>`,
|
|
@@ -253,7 +246,6 @@ export interface UseInfiniteQueryOptions<
|
|
|
253
246
|
> {
|
|
254
247
|
/**
|
|
255
248
|
* Set this to `false` to unsubscribe this observer from updates to the query cache.
|
|
256
|
-
*
|
|
257
249
|
* @defaultValue true
|
|
258
250
|
*/
|
|
259
251
|
subscribed?: boolean
|
|
@@ -269,7 +261,6 @@ export type AnyUseSuspenseInfiniteQueryOptions =
|
|
|
269
261
|
* The options accepted by `useSuspenseInfiniteQuery`. Same as {@link UseInfiniteQueryOptions}, minus `enabled`,
|
|
270
262
|
* `throwOnError`, and `placeholderData` — Suspense hooks cannot render a "disabled" or "placeholder" state, so
|
|
271
263
|
* those options don't apply.
|
|
272
|
-
*
|
|
273
264
|
* @template TQueryFnData - The type of a single page, as your `queryFn` resolves it.
|
|
274
265
|
* @template TError - The type of errors your `queryFn` may throw.
|
|
275
266
|
* @template TData - The type `data` ends up as after `select` runs — defaults to `InfiniteData<TQueryFnData>`,
|
|
@@ -307,7 +298,6 @@ export interface UseSuspenseInfiniteQueryOptions<
|
|
|
307
298
|
* The result of `useQuery` when `initialData` isn't set — `data` may be `undefined` while the query is
|
|
308
299
|
* `pending`. Re-exports {@link QueryObserverResult} from `@tanstack/query-core`. `useInfiniteQuery` returns
|
|
309
300
|
* {@link UseInfiniteQueryResult} instead.
|
|
310
|
-
*
|
|
311
301
|
* @template TData - The type `data` ends up as after `select` runs.
|
|
312
302
|
* @template TError - The type of errors your `queryFn` may throw.
|
|
313
303
|
*/
|
|
@@ -318,7 +308,6 @@ export type UseBaseQueryResult<
|
|
|
318
308
|
|
|
319
309
|
/**
|
|
320
310
|
* The result of `useQuery`. Same as {@link UseBaseQueryResult}.
|
|
321
|
-
*
|
|
322
311
|
* @template TData - The type `data` ends up as after `select` runs.
|
|
323
312
|
* @template TError - The type of errors your `queryFn` may throw.
|
|
324
313
|
*/
|
|
@@ -330,7 +319,6 @@ export type UseQueryResult<
|
|
|
330
319
|
/**
|
|
331
320
|
* The result of `useSuspenseQuery`. Same as {@link DefinedUseQueryResult}, minus `isPlaceholderData` — always
|
|
332
321
|
* `false` on that type, so this drops the dead field rather than an active state.
|
|
333
|
-
*
|
|
334
322
|
* @template TData - The type `data` ends up as after `select` runs.
|
|
335
323
|
* @template TError - The type of errors your `queryFn` may throw.
|
|
336
324
|
*/
|
|
@@ -346,7 +334,6 @@ export type UseSuspenseQueryResult<
|
|
|
346
334
|
* The result of `useQuery` when `initialData` is set, or of `useSuspenseQuery` before the `isPlaceholderData`
|
|
347
335
|
* omission — `data` is never `undefined` (unless a `select` changes `TData` to include `undefined`).
|
|
348
336
|
* Re-exports {@link DefinedQueryObserverResult} from `@tanstack/query-core`.
|
|
349
|
-
*
|
|
350
337
|
* @template TData - The type `data` ends up as after `select` runs.
|
|
351
338
|
* @template TError - The type of errors your `queryFn` may throw.
|
|
352
339
|
*/
|
|
@@ -358,7 +345,6 @@ export type DefinedUseQueryResult<
|
|
|
358
345
|
/**
|
|
359
346
|
* The result of `useInfiniteQuery` when `initialData` isn't set — `data` may be `undefined` while the query is
|
|
360
347
|
* `pending`. Re-exports {@link InfiniteQueryObserverResult} from `@tanstack/query-core`.
|
|
361
|
-
*
|
|
362
348
|
* @template TData - The type `data` ends up as after `select` runs.
|
|
363
349
|
* @template TError - The type of errors your `queryFn` may throw.
|
|
364
350
|
*/
|
|
@@ -371,7 +357,6 @@ export type UseInfiniteQueryResult<
|
|
|
371
357
|
* The result of `useInfiniteQuery` when `initialData` is set — `data` is never `undefined` (unless a
|
|
372
358
|
* `select` changes `TData` to include `undefined`). Re-exports {@link DefinedInfiniteQueryObserverResult}
|
|
373
359
|
* from `@tanstack/query-core`.
|
|
374
|
-
*
|
|
375
360
|
* @template TData - The type `data` ends up as after `select` runs.
|
|
376
361
|
* @template TError - The type of errors your `queryFn` may throw.
|
|
377
362
|
*/
|
|
@@ -383,7 +368,6 @@ export type DefinedUseInfiniteQueryResult<
|
|
|
383
368
|
/**
|
|
384
369
|
* The result of `useSuspenseInfiniteQuery`. Same as {@link DefinedUseInfiniteQueryResult}, minus
|
|
385
370
|
* `isPlaceholderData` — Suspense hooks never render placeholder data.
|
|
386
|
-
*
|
|
387
371
|
* @template TData - The type `data` ends up as after `select` runs.
|
|
388
372
|
* @template TError - The type of errors your `queryFn` may throw.
|
|
389
373
|
*/
|
|
@@ -403,7 +387,6 @@ export type AnyUseMutationOptions = UseMutationOptions<any, any, any, any>
|
|
|
403
387
|
/**
|
|
404
388
|
* The options accepted by `useMutation`. Same as {@link MutationObserverOptions} from `@tanstack/query-core`,
|
|
405
389
|
* minus the internal `_defaulted` flag.
|
|
406
|
-
*
|
|
407
390
|
* @template TData - The type your mutation function resolves to.
|
|
408
391
|
* @template TError - The type of errors your mutation function may throw.
|
|
409
392
|
* @template TVariables - The type of the variable passed to `mutate`/`mutateAsync`.
|
|
@@ -423,8 +406,8 @@ export interface UseMutationOptions<
|
|
|
423
406
|
/**
|
|
424
407
|
* The type of `mutate`, as returned by `useMutation`. Forwards the variables (and an optional per-call
|
|
425
408
|
* `onSuccess`/`onError`/`onSettled`) to the underlying `mutate` call. Fire-and-forget — errors are surfaced
|
|
426
|
-
* through the mutation result
|
|
427
|
-
*
|
|
409
|
+
* through the mutation result instead of being thrown by `mutate`, unless `throwOnError` makes `useMutation`
|
|
410
|
+
* rethrow them.
|
|
428
411
|
* @template TData - The type your mutation function resolves to.
|
|
429
412
|
* @template TError - The type of errors your mutation function may throw.
|
|
430
413
|
* @template TVariables - The type of the variable passed to `mutate`.
|
|
@@ -445,7 +428,6 @@ export type UseMutateFunction<
|
|
|
445
428
|
/**
|
|
446
429
|
* The type of `mutateAsync`, as returned by `useMutation`. Similar to {@link UseMutateFunction}, but returns a
|
|
447
430
|
* promise which can be awaited.
|
|
448
|
-
*
|
|
449
431
|
* @template TData - The type your mutation function resolves to.
|
|
450
432
|
* @template TError - The type of errors your mutation function may throw.
|
|
451
433
|
* @template TVariables - The type of the variable passed to `mutateAsync`.
|
|
@@ -462,7 +444,6 @@ export type UseMutateAsyncFunction<
|
|
|
462
444
|
/**
|
|
463
445
|
* The result of `useMutation`. Same as {@link MutationObserverResult} from `@tanstack/query-core`, with
|
|
464
446
|
* `mutate` narrowed to the fire-and-forget {@link UseMutateFunction} signature, plus the added `mutateAsync`.
|
|
465
|
-
*
|
|
466
447
|
* @template TData - The type your mutation function resolves to.
|
|
467
448
|
* @template TError - The type of errors your mutation function may throw.
|
|
468
449
|
* @template TVariables - The type of the variable passed to `mutate`/`mutateAsync`.
|
|
@@ -491,7 +472,6 @@ export type UseBaseMutationResult<
|
|
|
491
472
|
|
|
492
473
|
/**
|
|
493
474
|
* The result of `useMutation`. Same as {@link UseBaseMutationResult}.
|
|
494
|
-
*
|
|
495
475
|
* @template TData - The type your mutation function resolves to.
|
|
496
476
|
* @template TError - The type of errors your mutation function may throw.
|
|
497
477
|
* @template TVariables - The type of the variable passed to `mutate`/`mutateAsync`.
|
package/src/useBaseQuery.ts
CHANGED
|
@@ -23,6 +23,19 @@ import type {
|
|
|
23
23
|
} from '@tanstack/query-core'
|
|
24
24
|
import type { UseBaseQueryOptions } from './types'
|
|
25
25
|
|
|
26
|
+
/**
|
|
27
|
+
* Base implementation shared by `useQuery`, `useInfiniteQuery`, `useSuspenseQuery`, and
|
|
28
|
+
* `useSuspenseInfiniteQuery`.
|
|
29
|
+
* @param options - The options passed to the calling hook.
|
|
30
|
+
* @param Observer - The observer class from query-core (`QueryObserver` or
|
|
31
|
+
* `InfiniteQueryObserver`).
|
|
32
|
+
* @param queryClient - Use this to use a custom `QueryClient`. Otherwise, the one from the nearest
|
|
33
|
+
* context will be used.
|
|
34
|
+
* @returns The query result, tracking which properties are read unless `notifyOnChangeProps` is
|
|
35
|
+
* set.
|
|
36
|
+
* @throws {Error} If `options` is not an object (outside production), or the query error when it should be
|
|
37
|
+
* thrown to the nearest error boundary (see `throwOnError`). While suspending, it throws a promise instead.
|
|
38
|
+
*/
|
|
26
39
|
export function useBaseQuery<
|
|
27
40
|
TQueryFnData,
|
|
28
41
|
TError,
|
package/src/useInfiniteQuery.ts
CHANGED
|
@@ -23,11 +23,6 @@ import type {
|
|
|
23
23
|
* `initialPageParam`, `getNextPageParam`, `getPreviousPageParam`, and `maxPages`.
|
|
24
24
|
*
|
|
25
25
|
* This overload is selected when `initialData` is set.
|
|
26
|
-
*
|
|
27
|
-
* @remarks Keep in mind that imperative fetch calls, such as `fetchNextPage`, may interfere with the default
|
|
28
|
-
* refetch behavior, resulting in outdated data. Make sure to call these functions only in response to user
|
|
29
|
-
* actions, or add conditions like `hasNextPage && !isFetching`.
|
|
30
|
-
* @see {@link infiniteQueryOptions} to share these options between `useInfiniteQuery` and imperative APIs like `queryClient.infiniteQuery`.
|
|
31
26
|
* @param options - The {@link DefinedInitialDataInfiniteOptions} to use — everything you can pass to `useInfiniteQuery`, with `initialData` set.
|
|
32
27
|
* @param queryClient - Use this to use a custom `QueryClient`. Otherwise, the one from the nearest context will
|
|
33
28
|
* be used.
|
|
@@ -35,7 +30,10 @@ import type {
|
|
|
35
30
|
* `hasNextPage`, `hasPreviousPage`, `isFetchingNextPage`, and `isFetchingPreviousPage`. `data.pages` and
|
|
36
31
|
* `data.pageParams` are also added, as long as a `select` doesn't change `TData` away from its default
|
|
37
32
|
* `InfiniteData<TQueryFnData>` shape.
|
|
38
|
-
*
|
|
33
|
+
* @remarks Keep in mind that imperative fetch calls, such as `fetchNextPage`, may interfere with the default
|
|
34
|
+
* refetch behavior, resulting in outdated data. Make sure to call these functions only in response to user
|
|
35
|
+
* actions, or add conditions like `hasNextPage && !isFetching`.
|
|
36
|
+
* @see {@link infiniteQueryOptions} to share these options between `useInfiniteQuery` and imperative APIs like `queryClient.infiniteQuery`.
|
|
39
37
|
* @example
|
|
40
38
|
* ```tsx
|
|
41
39
|
* import { useInfiniteQuery } from '@tanstack/react-query'
|
|
@@ -82,11 +80,6 @@ export function useInfiniteQuery<
|
|
|
82
80
|
/**
|
|
83
81
|
* The options for `useInfiniteQuery` are identical to `useQuery`, with the addition of
|
|
84
82
|
* `initialPageParam`, `getNextPageParam`, `getPreviousPageParam`, and `maxPages`.
|
|
85
|
-
*
|
|
86
|
-
* @remarks Keep in mind that imperative fetch calls, such as `fetchNextPage`, may interfere with the default
|
|
87
|
-
* refetch behavior, resulting in outdated data. Make sure to call these functions only in response to user
|
|
88
|
-
* actions, or add conditions like `hasNextPage && !isFetching`.
|
|
89
|
-
* @see {@link infiniteQueryOptions} to share these options between `useInfiniteQuery` and imperative APIs like `queryClient.infiniteQuery`.
|
|
90
83
|
* @param options - The {@link UndefinedInitialDataInfiniteOptions} to use — everything you can pass to `useInfiniteQuery`.
|
|
91
84
|
* @param queryClient - Use this to use a custom `QueryClient`. Otherwise, the one from the nearest context will
|
|
92
85
|
* be used.
|
|
@@ -94,7 +87,10 @@ export function useInfiniteQuery<
|
|
|
94
87
|
* `hasNextPage`, `hasPreviousPage`, `isFetchingNextPage`, and `isFetchingPreviousPage`. `data.pages` and
|
|
95
88
|
* `data.pageParams` are also added, as long as a `select` doesn't change `TData` away from its default
|
|
96
89
|
* `InfiniteData<TQueryFnData>` shape.
|
|
97
|
-
*
|
|
90
|
+
* @remarks Keep in mind that imperative fetch calls, such as `fetchNextPage`, may interfere with the default
|
|
91
|
+
* refetch behavior, resulting in outdated data. Make sure to call these functions only in response to user
|
|
92
|
+
* actions, or add conditions like `hasNextPage && !isFetching`.
|
|
93
|
+
* @see {@link infiniteQueryOptions} to share these options between `useInfiniteQuery` and imperative APIs like `queryClient.infiniteQuery`.
|
|
98
94
|
* @example
|
|
99
95
|
* Fetching the next page from a "Load More" button click:
|
|
100
96
|
* ```tsx
|
|
@@ -133,7 +129,6 @@ export function useInfiniteQuery<
|
|
|
133
129
|
* )
|
|
134
130
|
* }
|
|
135
131
|
* ```
|
|
136
|
-
*
|
|
137
132
|
* @example
|
|
138
133
|
* Fetching the next page automatically as the user scrolls, using an `IntersectionObserver` on a
|
|
139
134
|
* sentinel element after the list:
|
|
@@ -208,11 +203,6 @@ export function useInfiniteQuery<
|
|
|
208
203
|
/**
|
|
209
204
|
* The options for `useInfiniteQuery` are identical to `useQuery`, with the addition of
|
|
210
205
|
* `initialPageParam`, `getNextPageParam`, `getPreviousPageParam`, and `maxPages`.
|
|
211
|
-
*
|
|
212
|
-
* @remarks Keep in mind that imperative fetch calls, such as `fetchNextPage`, may interfere with the default
|
|
213
|
-
* refetch behavior, resulting in outdated data. Make sure to call these functions only in response to user
|
|
214
|
-
* actions, or add conditions like `hasNextPage && !isFetching`.
|
|
215
|
-
* @see {@link infiniteQueryOptions} to share these options between `useInfiniteQuery` and imperative APIs like `queryClient.infiniteQuery`.
|
|
216
206
|
* @param options - The {@link UseInfiniteQueryOptions} to use — everything you can pass to `useInfiniteQuery`.
|
|
217
207
|
* @param queryClient - Use this to use a custom `QueryClient`. Otherwise, the one from the nearest context will
|
|
218
208
|
* be used.
|
|
@@ -220,7 +210,10 @@ export function useInfiniteQuery<
|
|
|
220
210
|
* `hasNextPage`, `hasPreviousPage`, `isFetchingNextPage`, and `isFetchingPreviousPage`. `data.pages` and
|
|
221
211
|
* `data.pageParams` are also added, as long as a `select` doesn't change `TData` away from its default
|
|
222
212
|
* `InfiniteData<TQueryFnData>` shape.
|
|
223
|
-
*
|
|
213
|
+
* @remarks Keep in mind that imperative fetch calls, such as `fetchNextPage`, may interfere with the default
|
|
214
|
+
* refetch behavior, resulting in outdated data. Make sure to call these functions only in response to user
|
|
215
|
+
* actions, or add conditions like `hasNextPage && !isFetching`.
|
|
216
|
+
* @see {@link infiniteQueryOptions} to share these options between `useInfiniteQuery` and imperative APIs like `queryClient.infiniteQuery`.
|
|
224
217
|
* @example
|
|
225
218
|
* Fetching the next page from a "Load More" button click:
|
|
226
219
|
* ```tsx
|
|
@@ -259,7 +252,6 @@ export function useInfiniteQuery<
|
|
|
259
252
|
* )
|
|
260
253
|
* }
|
|
261
254
|
* ```
|
|
262
|
-
*
|
|
263
255
|
* @example
|
|
264
256
|
* Fetching the next page automatically as the user scrolls, using an `IntersectionObserver` on a
|
|
265
257
|
* sentinel element after the list:
|
|
@@ -313,7 +305,6 @@ export function useInfiniteQuery<
|
|
|
313
305
|
* )
|
|
314
306
|
* }
|
|
315
307
|
* ```
|
|
316
|
-
*
|
|
317
308
|
* @example
|
|
318
309
|
* A query that's disabled, type safe, until `postId` is set — pass `skipToken` as `queryFn`
|
|
319
310
|
* instead of setting `enabled: false`:
|
package/src/useIsFetching.ts
CHANGED
|
@@ -8,13 +8,11 @@ import type { QueryClient, QueryFilters } from '@tanstack/query-core'
|
|
|
8
8
|
/**
|
|
9
9
|
* The `useIsFetching` hook returns the `number` of the queries that your application is loading or fetching in
|
|
10
10
|
* the background (useful for app-wide loading indicators).
|
|
11
|
-
*
|
|
12
11
|
* @param filters - The {@link QueryFilters} to narrow down the matched queries.
|
|
13
12
|
* @param queryClient - Use this to use a custom `QueryClient`. Otherwise, the one from the nearest context will
|
|
14
13
|
* be used.
|
|
15
14
|
* @returns Will be the `number` of the queries that your application is currently loading or fetching in the
|
|
16
15
|
* background.
|
|
17
|
-
*
|
|
18
16
|
* @example
|
|
19
17
|
* ```tsx
|
|
20
18
|
* import { useIsFetching } from '@tanstack/react-query'
|
|
@@ -26,7 +24,6 @@ import type { QueryClient, QueryFilters } from '@tanstack/query-core'
|
|
|
26
24
|
* return isFetchingPosts ? <span>Refreshing posts...</span> : null
|
|
27
25
|
* }
|
|
28
26
|
* ```
|
|
29
|
-
*
|
|
30
27
|
* @example
|
|
31
28
|
* A global loading indicator for any query fetching in the background, not just the ones on screen:
|
|
32
29
|
* ```tsx
|
package/src/useMutation.ts
CHANGED
|
@@ -19,9 +19,6 @@ import type { DefaultError, QueryClient } from '@tanstack/query-core'
|
|
|
19
19
|
/**
|
|
20
20
|
* Unlike queries, mutations are typically used to create/update/delete data or perform server side-effects.
|
|
21
21
|
* `useMutation` is the hook for that.
|
|
22
|
-
*
|
|
23
|
-
* @see {@link mutationOptions} to share these options across multiple `useMutation` call sites, or to look
|
|
24
|
-
* the mutation up elsewhere via its `mutationKey` (e.g. with `useMutationState`).
|
|
25
22
|
* @param options - The {@link UseMutationOptions} to use — everything you can pass to `useMutation`.
|
|
26
23
|
* @param queryClient - Use this to use a custom `QueryClient`. Otherwise, the one from the nearest context will
|
|
27
24
|
* be used.
|
|
@@ -30,7 +27,10 @@ import type { DefaultError, QueryClient } from '@tanstack/query-core'
|
|
|
30
27
|
* mutation definition. Hook-level callbacks (passed to `options`) fire for every mutation; per-call callbacks
|
|
31
28
|
* fire only for the latest call you've made, and only while the component is still mounted — unmounting before
|
|
32
29
|
* the mutation settles removes the subscription and prevents them from firing.
|
|
33
|
-
*
|
|
30
|
+
* @throws {Error} The mutation error, when `throwOnError` is `true` or returns `true` for it, so that it is
|
|
31
|
+
* thrown to the nearest error boundary.
|
|
32
|
+
* @see {@link mutationOptions} to share these options across multiple `useMutation` call sites, or to look
|
|
33
|
+
* the mutation up elsewhere via its `mutationKey` (e.g. with `useMutationState`).
|
|
34
34
|
* @example
|
|
35
35
|
* ```tsx
|
|
36
36
|
* import { useMutation, useQueryClient } from '@tanstack/react-query'
|
|
@@ -56,7 +56,6 @@ import type { DefaultError, QueryClient } from '@tanstack/query-core'
|
|
|
56
56
|
* )
|
|
57
57
|
* }
|
|
58
58
|
* ```
|
|
59
|
-
*
|
|
60
59
|
* @example
|
|
61
60
|
* Rendering the mutation's own state, rather than just firing it off:
|
|
62
61
|
* ```tsx
|
|
@@ -86,7 +85,6 @@ import type { DefaultError, QueryClient } from '@tanstack/query-core'
|
|
|
86
85
|
* )
|
|
87
86
|
* }
|
|
88
87
|
* ```
|
|
89
|
-
*
|
|
90
88
|
* @example
|
|
91
89
|
* Optimistic update via `onMutate`, rolling back on `onError`:
|
|
92
90
|
* ```tsx
|
|
@@ -122,7 +120,6 @@ import type { DefaultError, QueryClient } from '@tanstack/query-core'
|
|
|
122
120
|
* )
|
|
123
121
|
* }
|
|
124
122
|
* ```
|
|
125
|
-
*
|
|
126
123
|
* @example
|
|
127
124
|
* Callbacks passed per call to `mutate` only fire for the last call — `mutateAsync` gives you a
|
|
128
125
|
* promise per call instead, so you can wait for all of them when they succeed:
|
|
@@ -152,7 +149,6 @@ import type { DefaultError, QueryClient } from '@tanstack/query-core'
|
|
|
152
149
|
* )
|
|
153
150
|
* }
|
|
154
151
|
* ```
|
|
155
|
-
*
|
|
156
152
|
* @example
|
|
157
153
|
* If some of the mutations above can fail independently of the others, and you want to know which ones
|
|
158
154
|
* did — rather than losing that information the moment the first one rejects — swap `Promise.all` for
|
package/src/useMutationState.ts
CHANGED
|
@@ -14,12 +14,10 @@ import type {
|
|
|
14
14
|
/**
|
|
15
15
|
* The `useIsMutating` hook returns the `number` of mutations that your application currently has `pending`
|
|
16
16
|
* (useful for app-wide loading indicators).
|
|
17
|
-
*
|
|
18
17
|
* @param filters - The {@link MutationFilters} to narrow down the matched mutations.
|
|
19
18
|
* @param queryClient - Use this to use a custom `QueryClient`. Otherwise, the one from the nearest context will
|
|
20
19
|
* be used.
|
|
21
20
|
* @returns Will be the `number` of the mutations that your application currently has `pending`.
|
|
22
|
-
*
|
|
23
21
|
* @example
|
|
24
22
|
* ```tsx
|
|
25
23
|
* import { useIsMutating } from '@tanstack/react-query'
|
|
@@ -63,6 +61,13 @@ type MutationStateOptions<
|
|
|
63
61
|
select?: (mutation: TMutation) => TResult
|
|
64
62
|
}
|
|
65
63
|
|
|
64
|
+
/**
|
|
65
|
+
* Collects the mutations in the cache that match `options.filters`, mapped with `options.select`
|
|
66
|
+
* (or to their state, by default).
|
|
67
|
+
* @param mutationCache - The mutation cache to read.
|
|
68
|
+
* @param options - The `filters` to match and the `select` function to map each mutation with.
|
|
69
|
+
* @returns The selected value of every matching mutation.
|
|
70
|
+
*/
|
|
66
71
|
function getResult<
|
|
67
72
|
TResult = MutationState,
|
|
68
73
|
TMutation extends Mutation<any, any, any, any> =
|
|
@@ -85,13 +90,11 @@ function getResult<
|
|
|
85
90
|
* `useMutationState` is a hook that gives you access to all mutations in the `MutationCache`. You can pass
|
|
86
91
|
* `filters` ({@link MutationFilters}) to narrow down your mutations, and `select` to transform the mutation
|
|
87
92
|
* state.
|
|
88
|
-
*
|
|
89
93
|
* @param options - The `filters` to narrow down matched mutations, and an optional `select` to transform the
|
|
90
94
|
* mutation state.
|
|
91
95
|
* @param queryClient - Use this to use a custom `QueryClient`. Otherwise, the one from the nearest context will
|
|
92
96
|
* be used.
|
|
93
97
|
* @returns Will be an Array of whatever `select` returns for each matching mutation.
|
|
94
|
-
*
|
|
95
98
|
* @example
|
|
96
99
|
* Get all variables of all running mutations:
|
|
97
100
|
* ```tsx
|
|
@@ -106,7 +109,6 @@ function getResult<
|
|
|
106
109
|
* return <>{pendingVariables.length} posts saving...</>
|
|
107
110
|
* }
|
|
108
111
|
* ```
|
|
109
|
-
*
|
|
110
112
|
* @example
|
|
111
113
|
* Get all data for specific mutations via the `mutationKey`:
|
|
112
114
|
* ```tsx
|
|
@@ -134,7 +136,6 @@ function getResult<
|
|
|
134
136
|
* )
|
|
135
137
|
* }
|
|
136
138
|
* ```
|
|
137
|
-
*
|
|
138
139
|
* @example
|
|
139
140
|
* Access the latest successful mutation data via the `mutationKey`. Each invocation of `mutate` adds a new
|
|
140
141
|
* entry to the mutation cache for `gcTime` milliseconds — with the `status: 'success'` filter below, check the
|
|
@@ -164,9 +165,9 @@ export function useMutationState<
|
|
|
164
165
|
): Array<TResult> {
|
|
165
166
|
const mutationCache = useQueryClient(queryClient).getMutationCache()
|
|
166
167
|
const optionsRef = React.useRef(options)
|
|
167
|
-
const
|
|
168
|
-
if (
|
|
169
|
-
|
|
168
|
+
const resultRef = React.useRef<Array<TResult>>(null)
|
|
169
|
+
if (resultRef.current === null) {
|
|
170
|
+
resultRef.current = getResult(mutationCache, options)
|
|
170
171
|
}
|
|
171
172
|
|
|
172
173
|
React.useEffect(() => {
|
|
@@ -178,17 +179,17 @@ export function useMutationState<
|
|
|
178
179
|
(onStoreChange) =>
|
|
179
180
|
mutationCache.subscribe(() => {
|
|
180
181
|
const nextResult = replaceEqualDeep(
|
|
181
|
-
|
|
182
|
+
resultRef.current,
|
|
182
183
|
getResult(mutationCache, optionsRef.current),
|
|
183
184
|
)
|
|
184
|
-
if (
|
|
185
|
-
|
|
185
|
+
if (resultRef.current !== nextResult) {
|
|
186
|
+
resultRef.current = nextResult
|
|
186
187
|
notifyManager.schedule(onStoreChange)
|
|
187
188
|
}
|
|
188
189
|
}),
|
|
189
190
|
[mutationCache],
|
|
190
191
|
),
|
|
191
|
-
() =>
|
|
192
|
-
() =>
|
|
192
|
+
() => resultRef.current,
|
|
193
|
+
() => resultRef.current,
|
|
193
194
|
)!
|
|
194
195
|
}
|
|
@@ -23,12 +23,9 @@ import type { UsePrefetchInfiniteQueryOptions } from './types'
|
|
|
23
23
|
* The prefetch is skipped if the query already has any cached state — including a `pending`/`error` state left
|
|
24
24
|
* over from a previous attempt — so calling this on every render is cheap and won't refetch data that's
|
|
25
25
|
* already there or already in flight.
|
|
26
|
-
*
|
|
27
26
|
* @param options - The {@link UsePrefetchInfiniteQueryOptions} to use — everything you can pass to `queryClient.infiniteQuery`.
|
|
28
27
|
* @param queryClient - Use this to use a custom `QueryClient`. Otherwise, the one from the nearest context will
|
|
29
28
|
* be used.
|
|
30
|
-
* @returns `void` — nothing is returned.
|
|
31
|
-
*
|
|
32
29
|
* @example
|
|
33
30
|
* ```tsx
|
|
34
31
|
* import { Suspense } from 'react'
|
package/src/usePrefetchQuery.tsx
CHANGED
|
@@ -13,12 +13,9 @@ import type { UsePrefetchQueryOptions } from './types'
|
|
|
13
13
|
* The prefetch is skipped if the query already has any cached state — including a `pending`/`error` state left
|
|
14
14
|
* over from a previous attempt — so calling this on every render is cheap and won't refetch data that's
|
|
15
15
|
* already there or already in flight.
|
|
16
|
-
*
|
|
17
16
|
* @param options - The {@link UsePrefetchQueryOptions} to use — everything you can pass to `queryClient.query`.
|
|
18
17
|
* @param queryClient - Use this to use a custom `QueryClient`. Otherwise, the one from the nearest context will
|
|
19
18
|
* be used.
|
|
20
|
-
* @returns `void` — nothing is returned.
|
|
21
|
-
*
|
|
22
19
|
* @example
|
|
23
20
|
* ```tsx
|
|
24
21
|
* import { Suspense } from 'react'
|
package/src/useQueries.ts
CHANGED
|
@@ -150,7 +150,6 @@ type GetUseQueryResult<T> =
|
|
|
150
150
|
* matches a query options object is mapped per-element instead, still inferring each entry individually; any
|
|
151
151
|
* other non-tuple array — one whose element type doesn't match the expected options shape — falls back to
|
|
152
152
|
* that same homogeneous options type too.
|
|
153
|
-
*
|
|
154
153
|
* @template T - The type of the `queries` array as written at the call site.
|
|
155
154
|
* @template TResults - The internal accumulator that this type builds during recursion. It is not meant
|
|
156
155
|
* to be set explicitly.
|
|
@@ -201,7 +200,6 @@ export type QueriesOptions<
|
|
|
201
200
|
* tuple element's result type is inferred individually, up to 20 elements. A non-tuple array is mapped
|
|
202
201
|
* per-element instead, still inferring each entry individually; only past 20 elements does this fall back to a
|
|
203
202
|
* single homogeneous {@link UseQueryResult} type.
|
|
204
|
-
*
|
|
205
203
|
* @template T - The type of the `queries` array, as inferred by {@link QueriesOptions}.
|
|
206
204
|
* @template TResults - The internal accumulator that this type builds during recursion. It is not meant
|
|
207
205
|
* to be set explicitly.
|
|
@@ -239,7 +237,13 @@ export type QueriesResults<
|
|
|
239
237
|
*
|
|
240
238
|
* The `combine` option can be used to combine the results of the queries into a single value. The result will
|
|
241
239
|
* be structurally shared to be as referentially stable as possible.
|
|
242
|
-
*
|
|
240
|
+
* @param options - The `queries` array to run, and the optional `combine` and `subscribed` options.
|
|
241
|
+
* @param queryClient - Use this to provide a custom `QueryClient`. Otherwise, the one from the nearest context
|
|
242
|
+
* will be used.
|
|
243
|
+
* @returns The combined result. Without `combine`, this is an array with all the query results, in the same
|
|
244
|
+
* order as the input. When `combine` is provided, this is the value returned by `combine` instead.
|
|
245
|
+
* @throws {Error} The error of the first query that should be thrown to the nearest error boundary (see
|
|
246
|
+
* `throwOnError`). While suspending, it throws a promise instead.
|
|
243
247
|
* @remarks The `combine` function only re-runs if it changed referentially, or if any of the query results
|
|
244
248
|
* changed. An inlined `combine` function, as shown in the example below, therefore runs on every render — wrap
|
|
245
249
|
* it in `useCallback`, or extract it to a stable function reference if it doesn't have any dependencies, to
|
|
@@ -255,11 +259,6 @@ export type QueriesResults<
|
|
|
255
259
|
*
|
|
256
260
|
* `placeholderData` is supported here too, but unlike `useQuery`, it doesn't receive information from
|
|
257
261
|
* previously rendered queries, because the number of queries can differ between renders.
|
|
258
|
-
* @param queryClient - Use this to provide a custom `QueryClient`. Otherwise, the one from the nearest context
|
|
259
|
-
* will be used.
|
|
260
|
-
* @returns The combined result. Without `combine`, this is an array with all the query results, in the same
|
|
261
|
-
* order as the input. When `combine` is provided, this is the value returned by `combine` instead.
|
|
262
|
-
*
|
|
263
262
|
* @example
|
|
264
263
|
* ```tsx
|
|
265
264
|
* import { useQueries } from '@tanstack/react-query'
|
|
@@ -284,7 +283,6 @@ export type QueriesResults<
|
|
|
284
283
|
* )
|
|
285
284
|
* }
|
|
286
285
|
* ```
|
|
287
|
-
*
|
|
288
286
|
* @example
|
|
289
287
|
* Combining results into a single value:
|
|
290
288
|
* ```tsx
|
|
@@ -317,7 +315,6 @@ export type QueriesResults<
|
|
|
317
315
|
* )
|
|
318
316
|
* }
|
|
319
317
|
* ```
|
|
320
|
-
*
|
|
321
318
|
* @example
|
|
322
319
|
* Typing `select` via {@link queryOptions}. Note that spreading a `queryOptions` result and overriding
|
|
323
320
|
* `select` inline still falls back to `unknown` — wrap the spread in `queryOptions` again so the override is
|
|
@@ -380,7 +377,6 @@ export function useQueries<
|
|
|
380
377
|
combine?: (result: QueriesResults<T>) => TCombinedResult
|
|
381
378
|
/**
|
|
382
379
|
* Set this to `false` to unsubscribe this observer from updates to the query cache.
|
|
383
|
-
*
|
|
384
380
|
* @defaultValue true
|
|
385
381
|
*/
|
|
386
382
|
subscribed?: boolean
|
package/src/useQuery.ts
CHANGED
|
@@ -15,15 +15,13 @@ import type {
|
|
|
15
15
|
/**
|
|
16
16
|
* This overload is selected when `initialData` is set, so the resulting `data` is never `undefined` (unless
|
|
17
17
|
* a `select` changes `TData` to include `undefined`).
|
|
18
|
-
*
|
|
19
|
-
* @see {@link queryOptions} to share these options between `useQuery` and imperative APIs like `queryClient.query`.
|
|
20
18
|
* @param options - The {@link DefinedInitialDataOptions} to use — everything you can pass to `useQuery`, with `initialData` set.
|
|
21
19
|
* @param queryClient - Use this to use a custom `QueryClient`. Otherwise, the one from the nearest context will
|
|
22
20
|
* be used.
|
|
23
21
|
* @returns The current query result, typed so that `status` is `success` — or `error` if a fetch attempt
|
|
24
22
|
* fails while keeping the existing data (`status` never resolves to `pending` in this overload's type,
|
|
25
23
|
* since `initialData` guarantees data upfront). `isSuccess`/`isError` are derived booleans for convenience.
|
|
26
|
-
*
|
|
24
|
+
* @see {@link queryOptions} to share these options between `useQuery` and imperative APIs like `queryClient.query`.
|
|
27
25
|
* @example
|
|
28
26
|
* ```tsx
|
|
29
27
|
* import { useQuery } from '@tanstack/react-query'
|
|
@@ -59,14 +57,15 @@ export function useQuery<
|
|
|
59
57
|
): DefinedUseQueryResult<TData, TError>
|
|
60
58
|
|
|
61
59
|
/**
|
|
62
|
-
*
|
|
60
|
+
* This overload is selected when `initialData` is omitted or may be `undefined`, so the resulting `data`
|
|
61
|
+
* can be `undefined`.
|
|
63
62
|
* @param options - The {@link UndefinedInitialDataOptions} to use — everything you can pass to `useQuery`.
|
|
64
63
|
* @param queryClient - Use this to use a custom `QueryClient`. Otherwise, the one from the nearest context will
|
|
65
64
|
* be used.
|
|
66
65
|
* @returns The current query result. `status` is `pending` if there is no cached data to display, `error` if
|
|
67
66
|
* the last fetch attempt failed, or `success` if the query has data to display. `isPending`/`isSuccess`/`isError`
|
|
68
67
|
* are derived booleans for convenience.
|
|
69
|
-
*
|
|
68
|
+
* @see {@link queryOptions} to share these options between `useQuery` and imperative APIs like `queryClient.query`.
|
|
70
69
|
* @example
|
|
71
70
|
* ```tsx
|
|
72
71
|
* import { useQuery } from '@tanstack/react-query'
|
|
@@ -92,7 +91,6 @@ export function useQuery<
|
|
|
92
91
|
* )
|
|
93
92
|
* }
|
|
94
93
|
* ```
|
|
95
|
-
*
|
|
96
94
|
* @example
|
|
97
95
|
* The same query, checking `isPending`/`isError` instead of `status` — pick whichever reads better to you:
|
|
98
96
|
* ```tsx
|
|
@@ -126,14 +124,16 @@ export function useQuery<
|
|
|
126
124
|
): UseQueryResult<TData, TError>
|
|
127
125
|
|
|
128
126
|
/**
|
|
129
|
-
*
|
|
127
|
+
* Fallback overload for options whose `initialData` presence isn't statically known — for example, an
|
|
128
|
+
* object typed as {@link UseQueryOptions} rather than an object literal. Prefer one of the other overloads
|
|
129
|
+
* when possible, since they infer whether `data` can be `undefined` from `initialData` directly.
|
|
130
130
|
* @param options - The {@link UseQueryOptions} to use — everything you can pass to `useQuery`.
|
|
131
131
|
* @param queryClient - Use this to use a custom `QueryClient`. Otherwise, the one from the nearest context will
|
|
132
132
|
* be used.
|
|
133
133
|
* @returns The current query result. `status` is `pending` if there is no cached data to display, `error` if
|
|
134
134
|
* the last fetch attempt failed, or `success` if the query has data to display. `isPending`/`isSuccess`/`isError`
|
|
135
135
|
* are derived booleans for convenience.
|
|
136
|
-
*
|
|
136
|
+
* @see {@link queryOptions} to share these options between `useQuery` and imperative APIs like `queryClient.query`.
|
|
137
137
|
* @example
|
|
138
138
|
* ```tsx
|
|
139
139
|
* import { useQuery } from '@tanstack/react-query'
|
|
@@ -159,7 +159,6 @@ export function useQuery<
|
|
|
159
159
|
* )
|
|
160
160
|
* }
|
|
161
161
|
* ```
|
|
162
|
-
*
|
|
163
162
|
* @example
|
|
164
163
|
* `select` derives whatever `data` a component needs from the cached value, without changing what's
|
|
165
164
|
* actually stored in the cache — the cache still holds the full `Post[]`, but `data` here is a `number`:
|
|
@@ -179,7 +178,6 @@ export function useQuery<
|
|
|
179
178
|
* return <span>{data} posts</span>
|
|
180
179
|
* }
|
|
181
180
|
* ```
|
|
182
|
-
*
|
|
183
181
|
* @example
|
|
184
182
|
* A dependent query, only enabled once `postId` is set — use `isLoading`, not `isPending`, so the
|
|
185
183
|
* loading state doesn't show while the query is disabled:
|
|
@@ -200,7 +198,6 @@ export function useQuery<
|
|
|
200
198
|
* return <h1>{data?.title}</h1>
|
|
201
199
|
* }
|
|
202
200
|
* ```
|
|
203
|
-
*
|
|
204
201
|
* @example
|
|
205
202
|
* The same dependent query, type safe: `skipToken` disables the query without needing the
|
|
206
203
|
* non-null assertion above, since `queryFn` is only ever called when `postId` is defined.
|
|
@@ -222,7 +219,6 @@ export function useQuery<
|
|
|
222
219
|
* return <h1>{data?.title}</h1>
|
|
223
220
|
* }
|
|
224
221
|
* ```
|
|
225
|
-
*
|
|
226
222
|
* @example
|
|
227
223
|
* Seeding a detail query from an already-cached list, to skip the loading state. `initialDataUpdatedAt` carries
|
|
228
224
|
* over the list's own fetch time, so that if you set a `staleTime`, it's measured from when the list was
|
|
@@ -249,7 +245,6 @@ export function useQuery<
|
|
|
249
245
|
* return <h1>{data?.title}</h1>
|
|
250
246
|
* }
|
|
251
247
|
* ```
|
|
252
|
-
*
|
|
253
248
|
* @example
|
|
254
249
|
* Paginated data, keeping the previous page's data visible while the next page loads:
|
|
255
250
|
* ```tsx
|