@tanstack/react-query 5.104.1 → 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 +7 -6
- 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 +7 -6
- 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 +7 -6
- 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 +7 -6
- 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 +6 -6
- 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 +7 -6
- 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
|
@@ -1,6 +1,19 @@
|
|
|
1
1
|
import { UseBaseQueryOptions } from "./types.cjs";
|
|
2
2
|
import { QueryClient, QueryKey, QueryObserver, QueryObserverResult } from "@tanstack/query-core";
|
|
3
3
|
//#region src/useBaseQuery.d.ts
|
|
4
|
+
/**
|
|
5
|
+
* Base implementation shared by `useQuery`, `useInfiniteQuery`, `useSuspenseQuery`, and
|
|
6
|
+
* `useSuspenseInfiniteQuery`.
|
|
7
|
+
* @param options - The options passed to the calling hook.
|
|
8
|
+
* @param Observer - The observer class from query-core (`QueryObserver` or
|
|
9
|
+
* `InfiniteQueryObserver`).
|
|
10
|
+
* @param queryClient - Use this to use a custom `QueryClient`. Otherwise, the one from the nearest
|
|
11
|
+
* context will be used.
|
|
12
|
+
* @returns The query result, tracking which properties are read unless `notifyOnChangeProps` is
|
|
13
|
+
* set.
|
|
14
|
+
* @throws {Error} If `options` is not an object (outside production), or the query error when it should be
|
|
15
|
+
* thrown to the nearest error boundary (see `throwOnError`). While suspending, it throws a promise instead.
|
|
16
|
+
*/
|
|
4
17
|
export declare function useBaseQuery<TQueryFnData, TError, TData, TQueryData, TQueryKey extends QueryKey>(options: UseBaseQueryOptions<TQueryFnData, TError, TData, TQueryData, TQueryKey>, Observer: typeof QueryObserver, queryClient?: QueryClient): QueryObserverResult<TData, TError>;
|
|
5
18
|
//#endregion
|
|
6
19
|
//# sourceMappingURL=useBaseQuery.d.cts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useBaseQuery.d.cts","names":[],"sources":["../../src/useBaseQuery.ts"],"mappings":"
|
|
1
|
+
{"version":3,"file":"useBaseQuery.d.cts","names":[],"sources":["../../src/useBaseQuery.ts"],"mappings":";;;;;;;;;;;;;;;;wBAsCgB,aACd,cACA,QACA,OACA,YACA,kBAAkB,UAElB,SAAS,oBACP,cACA,QACA,OACA,YACA,YAEF,iBAAiB,eACjB,cAAc,cACb,oBAAoB,OAAO"}
|
|
@@ -1,6 +1,19 @@
|
|
|
1
1
|
import { UseBaseQueryOptions } from "./types.js";
|
|
2
2
|
import { QueryClient, QueryKey, QueryObserver, QueryObserverResult } from "@tanstack/query-core";
|
|
3
3
|
//#region src/useBaseQuery.d.ts
|
|
4
|
+
/**
|
|
5
|
+
* Base implementation shared by `useQuery`, `useInfiniteQuery`, `useSuspenseQuery`, and
|
|
6
|
+
* `useSuspenseInfiniteQuery`.
|
|
7
|
+
* @param options - The options passed to the calling hook.
|
|
8
|
+
* @param Observer - The observer class from query-core (`QueryObserver` or
|
|
9
|
+
* `InfiniteQueryObserver`).
|
|
10
|
+
* @param queryClient - Use this to use a custom `QueryClient`. Otherwise, the one from the nearest
|
|
11
|
+
* context will be used.
|
|
12
|
+
* @returns The query result, tracking which properties are read unless `notifyOnChangeProps` is
|
|
13
|
+
* set.
|
|
14
|
+
* @throws {Error} If `options` is not an object (outside production), or the query error when it should be
|
|
15
|
+
* thrown to the nearest error boundary (see `throwOnError`). While suspending, it throws a promise instead.
|
|
16
|
+
*/
|
|
4
17
|
export declare function useBaseQuery<TQueryFnData, TError, TData, TQueryData, TQueryKey extends QueryKey>(options: UseBaseQueryOptions<TQueryFnData, TError, TData, TQueryData, TQueryKey>, Observer: typeof QueryObserver, queryClient?: QueryClient): QueryObserverResult<TData, TError>;
|
|
5
18
|
//#endregion
|
|
6
19
|
//# sourceMappingURL=useBaseQuery.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useBaseQuery.d.ts","names":[],"sources":["../../src/useBaseQuery.ts"],"mappings":"
|
|
1
|
+
{"version":3,"file":"useBaseQuery.d.ts","names":[],"sources":["../../src/useBaseQuery.ts"],"mappings":";;;;;;;;;;;;;;;;wBAsCgB,aACd,cACA,QACA,OACA,YACA,kBAAkB,UAElB,SAAS,oBACP,cACA,QACA,OACA,YACA,YAEF,iBAAiB,eACjB,cAAc,cACb,oBAAoB,OAAO"}
|
|
@@ -7,6 +7,19 @@ import { ensureSuspenseTimers, fetchOptimistic, shouldSuspend } from "./suspense
|
|
|
7
7
|
import * as React from "react";
|
|
8
8
|
import { noop, notifyManager } from "@tanstack/query-core";
|
|
9
9
|
//#region src/useBaseQuery.ts
|
|
10
|
+
/**
|
|
11
|
+
* Base implementation shared by `useQuery`, `useInfiniteQuery`, `useSuspenseQuery`, and
|
|
12
|
+
* `useSuspenseInfiniteQuery`.
|
|
13
|
+
* @param options - The options passed to the calling hook.
|
|
14
|
+
* @param Observer - The observer class from query-core (`QueryObserver` or
|
|
15
|
+
* `InfiniteQueryObserver`).
|
|
16
|
+
* @param queryClient - Use this to use a custom `QueryClient`. Otherwise, the one from the nearest
|
|
17
|
+
* context will be used.
|
|
18
|
+
* @returns The query result, tracking which properties are read unless `notifyOnChangeProps` is
|
|
19
|
+
* set.
|
|
20
|
+
* @throws {Error} If `options` is not an object (outside production), or the query error when it should be
|
|
21
|
+
* thrown to the nearest error boundary (see `throwOnError`). While suspending, it throws a promise instead.
|
|
22
|
+
*/
|
|
10
23
|
function useBaseQuery(options, Observer, queryClient) {
|
|
11
24
|
if (process.env.NODE_ENV !== "production") {
|
|
12
25
|
if (typeof options !== "object" || Array.isArray(options)) throw new Error("Bad argument type. Starting with v5, only the \"Object\" form is allowed when calling query related functions. Please use the error stack to find the culprit call. More info here: https://tanstack.com/query/latest/docs/react/guides/migrating-to-v5#supports-a-single-signature-one-object");
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useBaseQuery.js","names":[],"sources":["../../src/useBaseQuery.ts"],"sourcesContent":["'use client'\nimport * as React from 'react'\n\nimport { noop, notifyManager } from '@tanstack/query-core'\nimport { useQueryClient } from './QueryClientProvider'\nimport { useQueryErrorResetBoundary } from './QueryErrorResetBoundary'\nimport {\n ensurePreventErrorBoundaryRetry,\n getHasError,\n useClearResetErrorBoundary,\n} from './errorBoundaryUtils'\nimport { useIsRestoring } from './IsRestoringProvider'\nimport {\n ensureSuspenseTimers,\n fetchOptimistic,\n shouldSuspend,\n} from './suspense'\nimport type {\n QueryClient,\n QueryKey,\n QueryObserver,\n QueryObserverResult,\n} from '@tanstack/query-core'\nimport type { UseBaseQueryOptions } from './types'\n\nexport function useBaseQuery<\n TQueryFnData,\n TError,\n TData,\n TQueryData,\n TQueryKey extends QueryKey,\n>(\n options: UseBaseQueryOptions<\n TQueryFnData,\n TError,\n TData,\n TQueryData,\n TQueryKey\n >,\n Observer: typeof QueryObserver,\n queryClient?: QueryClient,\n): QueryObserverResult<TData, TError> {\n if (process.env.NODE_ENV !== 'production') {\n if (typeof options !== 'object' || Array.isArray(options)) {\n throw new Error(\n 'Bad argument type. Starting with v5, only the \"Object\" form is allowed when calling query related functions. Please use the error stack to find the culprit call. More info here: https://tanstack.com/query/latest/docs/react/guides/migrating-to-v5#supports-a-single-signature-one-object',\n )\n }\n }\n\n const isRestoring = useIsRestoring()\n const errorResetBoundary = useQueryErrorResetBoundary()\n const client = useQueryClient(queryClient)\n const defaultedOptions = client.defaultQueryOptions(options)\n\n const query = client\n .getQueryCache()\n .get<TQueryFnData, TError, TQueryData, TQueryKey>(\n defaultedOptions.queryHash,\n )\n\n if (process.env.NODE_ENV !== 'production') {\n if (!defaultedOptions.queryFn) {\n console.error(\n `[${defaultedOptions.queryHash}]: No queryFn was passed as an option, and no default queryFn was found. The queryFn parameter is only optional when using a default queryFn. More info here: https://tanstack.com/query/latest/docs/framework/react/guides/default-query-function`,\n )\n }\n }\n\n const subscribed = options.subscribed !== false\n\n // Make sure results are optimistically set in fetching state before subscribing or updating options\n defaultedOptions._optimisticResults = isRestoring\n ? 'isRestoring'\n : subscribed\n ? 'optimistic'\n : undefined\n\n ensureSuspenseTimers(defaultedOptions)\n ensurePreventErrorBoundaryRetry(defaultedOptions, errorResetBoundary, query)\n useClearResetErrorBoundary(errorResetBoundary)\n\n const [observer] = React.useState(\n () =>\n new Observer<TQueryFnData, TError, TData, TQueryData, TQueryKey>(\n client,\n defaultedOptions,\n ),\n )\n\n // note: this must be called before useSyncExternalStore\n const result = observer.getOptimisticResult(defaultedOptions)\n\n const shouldSubscribe = !isRestoring && subscribed\n React.useSyncExternalStore(\n React.useCallback(\n (onStoreChange) => {\n const unsubscribe = shouldSubscribe\n ? observer.subscribe(notifyManager.batchCalls(onStoreChange))\n : noop\n\n // Update result to make sure we did not miss any query updates\n // between creating the observer and subscribing to it.\n observer.updateResult()\n\n return unsubscribe\n },\n [observer, shouldSubscribe],\n ),\n () => observer.getCurrentResult(),\n () => observer.getCurrentResult(),\n )\n\n React.useEffect(() => {\n observer.setOptions(defaultedOptions)\n }, [defaultedOptions, observer])\n\n // Handle suspense\n if (shouldSuspend(defaultedOptions, result)) {\n throw fetchOptimistic(defaultedOptions, observer, errorResetBoundary)\n }\n\n // Handle error boundary\n if (\n getHasError({\n result,\n errorResetBoundary,\n throwOnError: defaultedOptions.throwOnError,\n query,\n suspense: defaultedOptions.suspense,\n })\n ) {\n throw result.error\n }\n\n // Handle result property usage tracking\n return !defaultedOptions.notifyOnChangeProps\n ? observer.trackResult(result)\n : result\n}\n"],"mappings":"
|
|
1
|
+
{"version":3,"file":"useBaseQuery.js","names":[],"sources":["../../src/useBaseQuery.ts"],"sourcesContent":["'use client'\nimport * as React from 'react'\n\nimport { noop, notifyManager } from '@tanstack/query-core'\nimport { useQueryClient } from './QueryClientProvider'\nimport { useQueryErrorResetBoundary } from './QueryErrorResetBoundary'\nimport {\n ensurePreventErrorBoundaryRetry,\n getHasError,\n useClearResetErrorBoundary,\n} from './errorBoundaryUtils'\nimport { useIsRestoring } from './IsRestoringProvider'\nimport {\n ensureSuspenseTimers,\n fetchOptimistic,\n shouldSuspend,\n} from './suspense'\nimport type {\n QueryClient,\n QueryKey,\n QueryObserver,\n QueryObserverResult,\n} from '@tanstack/query-core'\nimport type { UseBaseQueryOptions } from './types'\n\n/**\n * Base implementation shared by `useQuery`, `useInfiniteQuery`, `useSuspenseQuery`, and\n * `useSuspenseInfiniteQuery`.\n * @param options - The options passed to the calling hook.\n * @param Observer - The observer class from query-core (`QueryObserver` or\n * `InfiniteQueryObserver`).\n * @param queryClient - Use this to use a custom `QueryClient`. Otherwise, the one from the nearest\n * context will be used.\n * @returns The query result, tracking which properties are read unless `notifyOnChangeProps` is\n * set.\n * @throws {Error} If `options` is not an object (outside production), or the query error when it should be\n * thrown to the nearest error boundary (see `throwOnError`). While suspending, it throws a promise instead.\n */\nexport function useBaseQuery<\n TQueryFnData,\n TError,\n TData,\n TQueryData,\n TQueryKey extends QueryKey,\n>(\n options: UseBaseQueryOptions<\n TQueryFnData,\n TError,\n TData,\n TQueryData,\n TQueryKey\n >,\n Observer: typeof QueryObserver,\n queryClient?: QueryClient,\n): QueryObserverResult<TData, TError> {\n if (process.env.NODE_ENV !== 'production') {\n if (typeof options !== 'object' || Array.isArray(options)) {\n throw new Error(\n 'Bad argument type. Starting with v5, only the \"Object\" form is allowed when calling query related functions. Please use the error stack to find the culprit call. More info here: https://tanstack.com/query/latest/docs/react/guides/migrating-to-v5#supports-a-single-signature-one-object',\n )\n }\n }\n\n const isRestoring = useIsRestoring()\n const errorResetBoundary = useQueryErrorResetBoundary()\n const client = useQueryClient(queryClient)\n const defaultedOptions = client.defaultQueryOptions(options)\n\n const query = client\n .getQueryCache()\n .get<TQueryFnData, TError, TQueryData, TQueryKey>(\n defaultedOptions.queryHash,\n )\n\n if (process.env.NODE_ENV !== 'production') {\n if (!defaultedOptions.queryFn) {\n console.error(\n `[${defaultedOptions.queryHash}]: No queryFn was passed as an option, and no default queryFn was found. The queryFn parameter is only optional when using a default queryFn. More info here: https://tanstack.com/query/latest/docs/framework/react/guides/default-query-function`,\n )\n }\n }\n\n const subscribed = options.subscribed !== false\n\n // Make sure results are optimistically set in fetching state before subscribing or updating options\n defaultedOptions._optimisticResults = isRestoring\n ? 'isRestoring'\n : subscribed\n ? 'optimistic'\n : undefined\n\n ensureSuspenseTimers(defaultedOptions)\n ensurePreventErrorBoundaryRetry(defaultedOptions, errorResetBoundary, query)\n useClearResetErrorBoundary(errorResetBoundary)\n\n const [observer] = React.useState(\n () =>\n new Observer<TQueryFnData, TError, TData, TQueryData, TQueryKey>(\n client,\n defaultedOptions,\n ),\n )\n\n // note: this must be called before useSyncExternalStore\n const result = observer.getOptimisticResult(defaultedOptions)\n\n const shouldSubscribe = !isRestoring && subscribed\n React.useSyncExternalStore(\n React.useCallback(\n (onStoreChange) => {\n const unsubscribe = shouldSubscribe\n ? observer.subscribe(notifyManager.batchCalls(onStoreChange))\n : noop\n\n // Update result to make sure we did not miss any query updates\n // between creating the observer and subscribing to it.\n observer.updateResult()\n\n return unsubscribe\n },\n [observer, shouldSubscribe],\n ),\n () => observer.getCurrentResult(),\n () => observer.getCurrentResult(),\n )\n\n React.useEffect(() => {\n observer.setOptions(defaultedOptions)\n }, [defaultedOptions, observer])\n\n // Handle suspense\n if (shouldSuspend(defaultedOptions, result)) {\n throw fetchOptimistic(defaultedOptions, observer, errorResetBoundary)\n }\n\n // Handle error boundary\n if (\n getHasError({\n result,\n errorResetBoundary,\n throwOnError: defaultedOptions.throwOnError,\n query,\n suspense: defaultedOptions.suspense,\n })\n ) {\n throw result.error\n }\n\n // Handle result property usage tracking\n return !defaultedOptions.notifyOnChangeProps\n ? observer.trackResult(result)\n : result\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;AAsCA,SAAgB,aAOd,SAOA,UACA,aACoC;CACpC,IAAI,QAAQ,IAAI,aAAa,cACvB;MAAA,OAAO,YAAY,YAAY,MAAM,QAAQ,OAAO,GACtD,MAAM,IAAI,MACR,gSACF;CAAA;CAIJ,MAAM,cAAc,eAAe;CACnC,MAAM,qBAAqB,2BAA2B;CACtD,MAAM,SAAS,eAAe,WAAW;CACzC,MAAM,mBAAmB,OAAO,oBAAoB,OAAO;CAE3D,MAAM,QAAQ,OACX,cAAc,CAAC,CACf,IACC,iBAAiB,SACnB;CAEF,IAAI,QAAQ,IAAI,aAAa,cACvB;MAAA,CAAC,iBAAiB,SACpB,QAAQ,MACN,IAAI,iBAAiB,UAAU,mPACjC;CAAA;CAIJ,MAAM,aAAa,QAAQ,eAAe;CAG1C,iBAAiB,qBAAqB,cAClC,gBACA,aACE,eACA,KAAA;CAEN,qBAAqB,gBAAgB;CACrC,gCAAgC,kBAAkB,oBAAoB,KAAK;CAC3E,2BAA2B,kBAAkB;CAE7C,MAAM,CAAC,YAAY,MAAM,eAErB,IAAI,SACF,QACA,gBACF,CACJ;CAGA,MAAM,SAAS,SAAS,oBAAoB,gBAAgB;CAE5D,MAAM,kBAAkB,CAAC,eAAe;CACxC,MAAM,qBACJ,MAAM,aACH,kBAAkB;EACjB,MAAM,cAAc,kBAChB,SAAS,UAAU,cAAc,WAAW,aAAa,CAAC,IAC1D;EAIJ,SAAS,aAAa;EAEtB,OAAO;CACT,GACA,CAAC,UAAU,eAAe,CAC5B,SACM,SAAS,iBAAiB,SAC1B,SAAS,iBAAiB,CAClC;CAEA,MAAM,gBAAgB;EACpB,SAAS,WAAW,gBAAgB;CACtC,GAAG,CAAC,kBAAkB,QAAQ,CAAC;CAG/B,IAAI,cAAc,kBAAkB,MAAM,GACxC,MAAM,gBAAgB,kBAAkB,UAAU,kBAAkB;CAItE,IACE,YAAY;EACV;EACA;EACA,cAAc,iBAAiB;EAC/B;EACA,UAAU,iBAAiB;CAC7B,CAAC,GAED,MAAM,OAAO;CAIf,OAAO,CAAC,iBAAiB,sBACrB,SAAS,YAAY,MAAM,IAC3B;AACN"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useInfiniteQuery.cjs","names":["useBaseQuery","InfiniteQueryObserver"],"sources":["../../src/useInfiniteQuery.ts"],"sourcesContent":["'use client'\nimport { InfiniteQueryObserver } from '@tanstack/query-core'\nimport { useBaseQuery } from './useBaseQuery'\nimport type {\n DefaultError,\n InfiniteData,\n QueryClient,\n QueryKey,\n QueryObserver,\n} from '@tanstack/query-core'\nimport type {\n DefinedUseInfiniteQueryResult,\n UseInfiniteQueryOptions,\n UseInfiniteQueryResult,\n} from './types'\nimport type {\n DefinedInitialDataInfiniteOptions,\n UndefinedInitialDataInfiniteOptions,\n} from './infiniteQueryOptions'\n\n/**\n * The options for `useInfiniteQuery` are identical to `useQuery`, with the addition of\n * `initialPageParam`, `getNextPageParam`, `getPreviousPageParam`, and `maxPages`.\n *\n * This overload is selected when `initialData` is set.\n *\n * @remarks Keep in mind that imperative fetch calls, such as `fetchNextPage`, may interfere with the default\n * refetch behavior, resulting in outdated data. Make sure to call these functions only in response to user\n * actions, or add conditions like `hasNextPage && !isFetching`.\n * @see {@link infiniteQueryOptions} to share these options between `useInfiniteQuery` and imperative APIs like `queryClient.infiniteQuery`.\n * @param options - The {@link DefinedInitialDataInfiniteOptions} to use — everything you can pass to `useInfiniteQuery`, with `initialData` set.\n * @param queryClient - Use this to use a custom `QueryClient`. Otherwise, the one from the nearest context will\n * be used.\n * @returns The same properties as `useQuery`, with the addition of `fetchNextPage`, `fetchPreviousPage`,\n * `hasNextPage`, `hasPreviousPage`, `isFetchingNextPage`, and `isFetchingPreviousPage`. `data.pages` and\n * `data.pageParams` are also added, as long as a `select` doesn't change `TData` away from its default\n * `InfiniteData<TQueryFnData>` shape.\n *\n * @example\n * ```tsx\n * import { useInfiniteQuery } from '@tanstack/react-query'\n *\n * function Projects() {\n * // `data` is never `undefined`, thanks to `initialData` — even if a refetch fails, so the\n * // list stays visible alongside the error.\n * const { data, isError, error } = useInfiniteQuery({\n * queryKey: ['projects'],\n * queryFn: ({ pageParam }) => fetchProjects(pageParam),\n * initialPageParam: 0,\n * getNextPageParam: (lastPage) => lastPage.nextId,\n * initialData: { pages: [], pageParams: [] },\n * })\n *\n * return (\n * <div>\n * {isError ? <span>Error: {error.message}</span> : null}\n * <ul>\n * {data.pages.map((page) => page.projects.map((p) => <li key={p.id}>{p.name}</li>))}\n * </ul>\n * </div>\n * )\n * }\n * ```\n */\nexport function useInfiniteQuery<\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 queryClient?: QueryClient,\n): DefinedUseInfiniteQueryResult<TData, TError>\n\n/**\n * The options for `useInfiniteQuery` are identical to `useQuery`, with the addition of\n * `initialPageParam`, `getNextPageParam`, `getPreviousPageParam`, and `maxPages`.\n *\n * @remarks Keep in mind that imperative fetch calls, such as `fetchNextPage`, may interfere with the default\n * refetch behavior, resulting in outdated data. Make sure to call these functions only in response to user\n * actions, or add conditions like `hasNextPage && !isFetching`.\n * @see {@link infiniteQueryOptions} to share these options between `useInfiniteQuery` and imperative APIs like `queryClient.infiniteQuery`.\n * @param options - The {@link UndefinedInitialDataInfiniteOptions} to use — everything you can pass to `useInfiniteQuery`.\n * @param queryClient - Use this to use a custom `QueryClient`. Otherwise, the one from the nearest context will\n * be used.\n * @returns The same properties as `useQuery`, with the addition of `fetchNextPage`, `fetchPreviousPage`,\n * `hasNextPage`, `hasPreviousPage`, `isFetchingNextPage`, and `isFetchingPreviousPage`. `data.pages` and\n * `data.pageParams` are also added, as long as a `select` doesn't change `TData` away from its default\n * `InfiniteData<TQueryFnData>` shape.\n *\n * @example\n * Fetching the next page from a \"Load More\" button click:\n * ```tsx\n * import { useInfiniteQuery } from '@tanstack/react-query'\n *\n * function Projects() {\n * const { data, isPending, isError, error, fetchNextPage, hasNextPage, isFetching, isFetchingNextPage } =\n * useInfiniteQuery({\n * queryKey: ['projects'],\n * queryFn: ({ pageParam }) => fetchProjects(pageParam),\n * initialPageParam: 0,\n * getNextPageParam: (lastPage) => lastPage.nextId,\n * })\n *\n * if (isPending) return 'Loading...'\n * if (isError) return <span>Error: {error.message}</span>\n *\n * return (\n * <>\n * <ul>\n * {data.pages.map((page) =>\n * page.projects.map((project) => <li key={project.id}>{project.name}</li>),\n * )}\n * </ul>\n * <button\n * onClick={() => fetchNextPage()}\n * disabled={!hasNextPage || isFetching}\n * >\n * {isFetchingNextPage\n * ? 'Loading more...'\n * : hasNextPage\n * ? 'Load More'\n * : 'Nothing more to load'}\n * </button>\n * </>\n * )\n * }\n * ```\n *\n * @example\n * Fetching the next page automatically as the user scrolls, using an `IntersectionObserver` on a\n * sentinel element after the list:\n * ```tsx\n * import { useInfiniteQuery } from '@tanstack/react-query'\n * import { useEffect, useRef } from 'react'\n *\n * function Projects() {\n * const {\n * data,\n * isPending,\n * isError,\n * error,\n * fetchNextPage,\n * hasNextPage,\n * isFetching,\n * isFetchingNextPage,\n * } = useInfiniteQuery({\n * queryKey: ['projects'],\n * queryFn: ({ pageParam }) => fetchProjects(pageParam),\n * initialPageParam: 0,\n * getNextPageParam: (lastPage) => lastPage.nextId,\n * })\n *\n * const sentinelRef = useRef<HTMLDivElement>(null)\n *\n * useEffect(() => {\n * const sentinel = sentinelRef.current\n * if (sentinel == null || !hasNextPage || isFetching) return\n *\n * const observer = new IntersectionObserver(([entry]) => {\n * if (entry?.isIntersecting) fetchNextPage()\n * })\n * observer.observe(sentinel)\n *\n * return () => observer.disconnect()\n * }, [hasNextPage, isFetching, fetchNextPage])\n *\n * if (isPending) return 'Loading...'\n * if (isError) return <span>Error: {error.message}</span>\n *\n * return (\n * <>\n * <ul>\n * {data.pages.map((page) =>\n * page.projects.map((project) => <li key={project.id}>{project.name}</li>),\n * )}\n * </ul>\n * <div ref={sentinelRef}>{isFetchingNextPage ? 'Loading more...' : null}</div>\n * </>\n * )\n * }\n * ```\n */\nexport function useInfiniteQuery<\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 queryClient?: QueryClient,\n): UseInfiniteQueryResult<TData, TError>\n\n/**\n * The options for `useInfiniteQuery` are identical to `useQuery`, with the addition of\n * `initialPageParam`, `getNextPageParam`, `getPreviousPageParam`, and `maxPages`.\n *\n * @remarks Keep in mind that imperative fetch calls, such as `fetchNextPage`, may interfere with the default\n * refetch behavior, resulting in outdated data. Make sure to call these functions only in response to user\n * actions, or add conditions like `hasNextPage && !isFetching`.\n * @see {@link infiniteQueryOptions} to share these options between `useInfiniteQuery` and imperative APIs like `queryClient.infiniteQuery`.\n * @param options - The {@link UseInfiniteQueryOptions} to use — everything you can pass to `useInfiniteQuery`.\n * @param queryClient - Use this to use a custom `QueryClient`. Otherwise, the one from the nearest context will\n * be used.\n * @returns The same properties as `useQuery`, with the addition of `fetchNextPage`, `fetchPreviousPage`,\n * `hasNextPage`, `hasPreviousPage`, `isFetchingNextPage`, and `isFetchingPreviousPage`. `data.pages` and\n * `data.pageParams` are also added, as long as a `select` doesn't change `TData` away from its default\n * `InfiniteData<TQueryFnData>` shape.\n *\n * @example\n * Fetching the next page from a \"Load More\" button click:\n * ```tsx\n * import { useInfiniteQuery } from '@tanstack/react-query'\n *\n * function Projects() {\n * const { data, isPending, isError, error, fetchNextPage, hasNextPage, isFetching, isFetchingNextPage } =\n * useInfiniteQuery({\n * queryKey: ['projects'],\n * queryFn: ({ pageParam }) => fetchProjects(pageParam),\n * initialPageParam: 0,\n * getNextPageParam: (lastPage) => lastPage.nextId,\n * })\n *\n * if (isPending) return 'Loading...'\n * if (isError) return <span>Error: {error.message}</span>\n *\n * return (\n * <>\n * <ul>\n * {data.pages.map((page) =>\n * page.projects.map((project) => <li key={project.id}>{project.name}</li>),\n * )}\n * </ul>\n * <button\n * onClick={() => fetchNextPage()}\n * disabled={!hasNextPage || isFetching}\n * >\n * {isFetchingNextPage\n * ? 'Loading more...'\n * : hasNextPage\n * ? 'Load More'\n * : 'Nothing more to load'}\n * </button>\n * </>\n * )\n * }\n * ```\n *\n * @example\n * Fetching the next page automatically as the user scrolls, using an `IntersectionObserver` on a\n * sentinel element after the list:\n * ```tsx\n * import { useInfiniteQuery } from '@tanstack/react-query'\n * import { useEffect, useRef } from 'react'\n *\n * function Projects() {\n * const {\n * data,\n * isPending,\n * isError,\n * error,\n * fetchNextPage,\n * hasNextPage,\n * isFetching,\n * isFetchingNextPage,\n * } = useInfiniteQuery({\n * queryKey: ['projects'],\n * queryFn: ({ pageParam }) => fetchProjects(pageParam),\n * initialPageParam: 0,\n * getNextPageParam: (lastPage) => lastPage.nextId,\n * })\n *\n * const sentinelRef = useRef<HTMLDivElement>(null)\n *\n * useEffect(() => {\n * const sentinel = sentinelRef.current\n * if (sentinel == null || !hasNextPage || isFetching) return\n *\n * const observer = new IntersectionObserver(([entry]) => {\n * if (entry?.isIntersecting) fetchNextPage()\n * })\n * observer.observe(sentinel)\n *\n * return () => observer.disconnect()\n * }, [hasNextPage, isFetching, fetchNextPage])\n *\n * if (isPending) return 'Loading...'\n * if (isError) return <span>Error: {error.message}</span>\n *\n * return (\n * <>\n * <ul>\n * {data.pages.map((page) =>\n * page.projects.map((project) => <li key={project.id}>{project.name}</li>),\n * )}\n * </ul>\n * <div ref={sentinelRef}>{isFetchingNextPage ? 'Loading more...' : null}</div>\n * </>\n * )\n * }\n * ```\n *\n * @example\n * A query that's disabled, type safe, until `postId` is set — pass `skipToken` as `queryFn`\n * instead of setting `enabled: false`:\n * ```tsx\n * import { skipToken, useInfiniteQuery } from '@tanstack/react-query'\n *\n * function Comments({ postId }: { postId: string | undefined }) {\n * // Use `isLoading`, not `isPending`, so the loading state doesn't show while the query is disabled.\n * const { data, isLoading, isError, error } = useInfiniteQuery({\n * queryKey: ['post', postId, 'comments'],\n * queryFn:\n * postId != null\n * ? ({ pageParam }) => fetchComments(postId, pageParam)\n * : skipToken,\n * initialPageParam: 0,\n * getNextPageParam: (lastPage) => lastPage.nextId,\n * })\n *\n * if (postId == null) return 'Select a post'\n * if (isLoading) return 'Loading...'\n * if (isError) return <span>Error: {error.message}</span>\n *\n * return (\n * <ul>\n * {data?.pages.map((page) => page.comments.map((c) => <li key={c.id}>{c.text}</li>))}\n * </ul>\n * )\n * }\n * ```\n */\nexport function useInfiniteQuery<\n TQueryFnData,\n TError = DefaultError,\n TData = InfiniteData<TQueryFnData>,\n TQueryKey extends QueryKey = QueryKey,\n TPageParam = unknown,\n>(\n options: UseInfiniteQueryOptions<\n TQueryFnData,\n TError,\n TData,\n TQueryKey,\n TPageParam\n >,\n queryClient?: QueryClient,\n): UseInfiniteQueryResult<TData, TError>\n\nexport function useInfiniteQuery(\n options: UseInfiniteQueryOptions,\n queryClient?: QueryClient,\n) {\n return useBaseQuery(\n options,\n InfiniteQueryObserver as typeof QueryObserver,\n queryClient,\n )\n}\n"],"mappings":";;;;;AA2WA,SAAgB,iBACd,SACA,aACA;CACA,OAAOA,qBAAAA,aACL,SACAC,qBAAAA,uBACA,WACF;AACF"}
|
|
1
|
+
{"version":3,"file":"useInfiniteQuery.cjs","names":["useBaseQuery","InfiniteQueryObserver"],"sources":["../../src/useInfiniteQuery.ts"],"sourcesContent":["'use client'\nimport { InfiniteQueryObserver } from '@tanstack/query-core'\nimport { useBaseQuery } from './useBaseQuery'\nimport type {\n DefaultError,\n InfiniteData,\n QueryClient,\n QueryKey,\n QueryObserver,\n} from '@tanstack/query-core'\nimport type {\n DefinedUseInfiniteQueryResult,\n UseInfiniteQueryOptions,\n UseInfiniteQueryResult,\n} from './types'\nimport type {\n DefinedInitialDataInfiniteOptions,\n UndefinedInitialDataInfiniteOptions,\n} from './infiniteQueryOptions'\n\n/**\n * The options for `useInfiniteQuery` are identical to `useQuery`, with the addition of\n * `initialPageParam`, `getNextPageParam`, `getPreviousPageParam`, and `maxPages`.\n *\n * This overload is selected when `initialData` is set.\n * @param options - The {@link DefinedInitialDataInfiniteOptions} to use — everything you can pass to `useInfiniteQuery`, with `initialData` set.\n * @param queryClient - Use this to use a custom `QueryClient`. Otherwise, the one from the nearest context will\n * be used.\n * @returns The same properties as `useQuery`, with the addition of `fetchNextPage`, `fetchPreviousPage`,\n * `hasNextPage`, `hasPreviousPage`, `isFetchingNextPage`, and `isFetchingPreviousPage`. `data.pages` and\n * `data.pageParams` are also added, as long as a `select` doesn't change `TData` away from its default\n * `InfiniteData<TQueryFnData>` shape.\n * @remarks Keep in mind that imperative fetch calls, such as `fetchNextPage`, may interfere with the default\n * refetch behavior, resulting in outdated data. Make sure to call these functions only in response to user\n * actions, or add conditions like `hasNextPage && !isFetching`.\n * @see {@link infiniteQueryOptions} to share these options between `useInfiniteQuery` and imperative APIs like `queryClient.infiniteQuery`.\n * @example\n * ```tsx\n * import { useInfiniteQuery } from '@tanstack/react-query'\n *\n * function Projects() {\n * // `data` is never `undefined`, thanks to `initialData` — even if a refetch fails, so the\n * // list stays visible alongside the error.\n * const { data, isError, error } = useInfiniteQuery({\n * queryKey: ['projects'],\n * queryFn: ({ pageParam }) => fetchProjects(pageParam),\n * initialPageParam: 0,\n * getNextPageParam: (lastPage) => lastPage.nextId,\n * initialData: { pages: [], pageParams: [] },\n * })\n *\n * return (\n * <div>\n * {isError ? <span>Error: {error.message}</span> : null}\n * <ul>\n * {data.pages.map((page) => page.projects.map((p) => <li key={p.id}>{p.name}</li>))}\n * </ul>\n * </div>\n * )\n * }\n * ```\n */\nexport function useInfiniteQuery<\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 queryClient?: QueryClient,\n): DefinedUseInfiniteQueryResult<TData, TError>\n\n/**\n * The options for `useInfiniteQuery` are identical to `useQuery`, with the addition of\n * `initialPageParam`, `getNextPageParam`, `getPreviousPageParam`, and `maxPages`.\n * @param options - The {@link UndefinedInitialDataInfiniteOptions} to use — everything you can pass to `useInfiniteQuery`.\n * @param queryClient - Use this to use a custom `QueryClient`. Otherwise, the one from the nearest context will\n * be used.\n * @returns The same properties as `useQuery`, with the addition of `fetchNextPage`, `fetchPreviousPage`,\n * `hasNextPage`, `hasPreviousPage`, `isFetchingNextPage`, and `isFetchingPreviousPage`. `data.pages` and\n * `data.pageParams` are also added, as long as a `select` doesn't change `TData` away from its default\n * `InfiniteData<TQueryFnData>` shape.\n * @remarks Keep in mind that imperative fetch calls, such as `fetchNextPage`, may interfere with the default\n * refetch behavior, resulting in outdated data. Make sure to call these functions only in response to user\n * actions, or add conditions like `hasNextPage && !isFetching`.\n * @see {@link infiniteQueryOptions} to share these options between `useInfiniteQuery` and imperative APIs like `queryClient.infiniteQuery`.\n * @example\n * Fetching the next page from a \"Load More\" button click:\n * ```tsx\n * import { useInfiniteQuery } from '@tanstack/react-query'\n *\n * function Projects() {\n * const { data, isPending, isError, error, fetchNextPage, hasNextPage, isFetching, isFetchingNextPage } =\n * useInfiniteQuery({\n * queryKey: ['projects'],\n * queryFn: ({ pageParam }) => fetchProjects(pageParam),\n * initialPageParam: 0,\n * getNextPageParam: (lastPage) => lastPage.nextId,\n * })\n *\n * if (isPending) return 'Loading...'\n * if (isError) return <span>Error: {error.message}</span>\n *\n * return (\n * <>\n * <ul>\n * {data.pages.map((page) =>\n * page.projects.map((project) => <li key={project.id}>{project.name}</li>),\n * )}\n * </ul>\n * <button\n * onClick={() => fetchNextPage()}\n * disabled={!hasNextPage || isFetching}\n * >\n * {isFetchingNextPage\n * ? 'Loading more...'\n * : hasNextPage\n * ? 'Load More'\n * : 'Nothing more to load'}\n * </button>\n * </>\n * )\n * }\n * ```\n * @example\n * Fetching the next page automatically as the user scrolls, using an `IntersectionObserver` on a\n * sentinel element after the list:\n * ```tsx\n * import { useInfiniteQuery } from '@tanstack/react-query'\n * import { useEffect, useRef } from 'react'\n *\n * function Projects() {\n * const {\n * data,\n * isPending,\n * isError,\n * error,\n * fetchNextPage,\n * hasNextPage,\n * isFetching,\n * isFetchingNextPage,\n * } = useInfiniteQuery({\n * queryKey: ['projects'],\n * queryFn: ({ pageParam }) => fetchProjects(pageParam),\n * initialPageParam: 0,\n * getNextPageParam: (lastPage) => lastPage.nextId,\n * })\n *\n * const sentinelRef = useRef<HTMLDivElement>(null)\n *\n * useEffect(() => {\n * const sentinel = sentinelRef.current\n * if (sentinel == null || !hasNextPage || isFetching) return\n *\n * const observer = new IntersectionObserver(([entry]) => {\n * if (entry?.isIntersecting) fetchNextPage()\n * })\n * observer.observe(sentinel)\n *\n * return () => observer.disconnect()\n * }, [hasNextPage, isFetching, fetchNextPage])\n *\n * if (isPending) return 'Loading...'\n * if (isError) return <span>Error: {error.message}</span>\n *\n * return (\n * <>\n * <ul>\n * {data.pages.map((page) =>\n * page.projects.map((project) => <li key={project.id}>{project.name}</li>),\n * )}\n * </ul>\n * <div ref={sentinelRef}>{isFetchingNextPage ? 'Loading more...' : null}</div>\n * </>\n * )\n * }\n * ```\n */\nexport function useInfiniteQuery<\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 queryClient?: QueryClient,\n): UseInfiniteQueryResult<TData, TError>\n\n/**\n * The options for `useInfiniteQuery` are identical to `useQuery`, with the addition of\n * `initialPageParam`, `getNextPageParam`, `getPreviousPageParam`, and `maxPages`.\n * @param options - The {@link UseInfiniteQueryOptions} to use — everything you can pass to `useInfiniteQuery`.\n * @param queryClient - Use this to use a custom `QueryClient`. Otherwise, the one from the nearest context will\n * be used.\n * @returns The same properties as `useQuery`, with the addition of `fetchNextPage`, `fetchPreviousPage`,\n * `hasNextPage`, `hasPreviousPage`, `isFetchingNextPage`, and `isFetchingPreviousPage`. `data.pages` and\n * `data.pageParams` are also added, as long as a `select` doesn't change `TData` away from its default\n * `InfiniteData<TQueryFnData>` shape.\n * @remarks Keep in mind that imperative fetch calls, such as `fetchNextPage`, may interfere with the default\n * refetch behavior, resulting in outdated data. Make sure to call these functions only in response to user\n * actions, or add conditions like `hasNextPage && !isFetching`.\n * @see {@link infiniteQueryOptions} to share these options between `useInfiniteQuery` and imperative APIs like `queryClient.infiniteQuery`.\n * @example\n * Fetching the next page from a \"Load More\" button click:\n * ```tsx\n * import { useInfiniteQuery } from '@tanstack/react-query'\n *\n * function Projects() {\n * const { data, isPending, isError, error, fetchNextPage, hasNextPage, isFetching, isFetchingNextPage } =\n * useInfiniteQuery({\n * queryKey: ['projects'],\n * queryFn: ({ pageParam }) => fetchProjects(pageParam),\n * initialPageParam: 0,\n * getNextPageParam: (lastPage) => lastPage.nextId,\n * })\n *\n * if (isPending) return 'Loading...'\n * if (isError) return <span>Error: {error.message}</span>\n *\n * return (\n * <>\n * <ul>\n * {data.pages.map((page) =>\n * page.projects.map((project) => <li key={project.id}>{project.name}</li>),\n * )}\n * </ul>\n * <button\n * onClick={() => fetchNextPage()}\n * disabled={!hasNextPage || isFetching}\n * >\n * {isFetchingNextPage\n * ? 'Loading more...'\n * : hasNextPage\n * ? 'Load More'\n * : 'Nothing more to load'}\n * </button>\n * </>\n * )\n * }\n * ```\n * @example\n * Fetching the next page automatically as the user scrolls, using an `IntersectionObserver` on a\n * sentinel element after the list:\n * ```tsx\n * import { useInfiniteQuery } from '@tanstack/react-query'\n * import { useEffect, useRef } from 'react'\n *\n * function Projects() {\n * const {\n * data,\n * isPending,\n * isError,\n * error,\n * fetchNextPage,\n * hasNextPage,\n * isFetching,\n * isFetchingNextPage,\n * } = useInfiniteQuery({\n * queryKey: ['projects'],\n * queryFn: ({ pageParam }) => fetchProjects(pageParam),\n * initialPageParam: 0,\n * getNextPageParam: (lastPage) => lastPage.nextId,\n * })\n *\n * const sentinelRef = useRef<HTMLDivElement>(null)\n *\n * useEffect(() => {\n * const sentinel = sentinelRef.current\n * if (sentinel == null || !hasNextPage || isFetching) return\n *\n * const observer = new IntersectionObserver(([entry]) => {\n * if (entry?.isIntersecting) fetchNextPage()\n * })\n * observer.observe(sentinel)\n *\n * return () => observer.disconnect()\n * }, [hasNextPage, isFetching, fetchNextPage])\n *\n * if (isPending) return 'Loading...'\n * if (isError) return <span>Error: {error.message}</span>\n *\n * return (\n * <>\n * <ul>\n * {data.pages.map((page) =>\n * page.projects.map((project) => <li key={project.id}>{project.name}</li>),\n * )}\n * </ul>\n * <div ref={sentinelRef}>{isFetchingNextPage ? 'Loading more...' : null}</div>\n * </>\n * )\n * }\n * ```\n * @example\n * A query that's disabled, type safe, until `postId` is set — pass `skipToken` as `queryFn`\n * instead of setting `enabled: false`:\n * ```tsx\n * import { skipToken, useInfiniteQuery } from '@tanstack/react-query'\n *\n * function Comments({ postId }: { postId: string | undefined }) {\n * // Use `isLoading`, not `isPending`, so the loading state doesn't show while the query is disabled.\n * const { data, isLoading, isError, error } = useInfiniteQuery({\n * queryKey: ['post', postId, 'comments'],\n * queryFn:\n * postId != null\n * ? ({ pageParam }) => fetchComments(postId, pageParam)\n * : skipToken,\n * initialPageParam: 0,\n * getNextPageParam: (lastPage) => lastPage.nextId,\n * })\n *\n * if (postId == null) return 'Select a post'\n * if (isLoading) return 'Loading...'\n * if (isError) return <span>Error: {error.message}</span>\n *\n * return (\n * <ul>\n * {data?.pages.map((page) => page.comments.map((c) => <li key={c.id}>{c.text}</li>))}\n * </ul>\n * )\n * }\n * ```\n */\nexport function useInfiniteQuery<\n TQueryFnData,\n TError = DefaultError,\n TData = InfiniteData<TQueryFnData>,\n TQueryKey extends QueryKey = QueryKey,\n TPageParam = unknown,\n>(\n options: UseInfiniteQueryOptions<\n TQueryFnData,\n TError,\n TData,\n TQueryKey,\n TPageParam\n >,\n queryClient?: QueryClient,\n): UseInfiniteQueryResult<TData, TError>\n\nexport function useInfiniteQuery(\n options: UseInfiniteQueryOptions,\n queryClient?: QueryClient,\n) {\n return useBaseQuery(\n options,\n InfiniteQueryObserver as typeof QueryObserver,\n queryClient,\n )\n}\n"],"mappings":";;;;;AAkWA,SAAgB,iBACd,SACA,aACA;CACA,OAAOA,qBAAAA,aACL,SACAC,qBAAAA,uBACA,WACF;AACF"}
|
|
@@ -7,11 +7,6 @@ import { DefaultError, InfiniteData, QueryClient, QueryKey } from "@tanstack/que
|
|
|
7
7
|
* `initialPageParam`, `getNextPageParam`, `getPreviousPageParam`, and `maxPages`.
|
|
8
8
|
*
|
|
9
9
|
* This overload is selected when `initialData` is set.
|
|
10
|
-
*
|
|
11
|
-
* @remarks Keep in mind that imperative fetch calls, such as `fetchNextPage`, may interfere with the default
|
|
12
|
-
* refetch behavior, resulting in outdated data. Make sure to call these functions only in response to user
|
|
13
|
-
* actions, or add conditions like `hasNextPage && !isFetching`.
|
|
14
|
-
* @see {@link infiniteQueryOptions} to share these options between `useInfiniteQuery` and imperative APIs like `queryClient.infiniteQuery`.
|
|
15
10
|
* @param options - The {@link DefinedInitialDataInfiniteOptions} to use — everything you can pass to `useInfiniteQuery`, with `initialData` set.
|
|
16
11
|
* @param queryClient - Use this to use a custom `QueryClient`. Otherwise, the one from the nearest context will
|
|
17
12
|
* be used.
|
|
@@ -19,7 +14,10 @@ import { DefaultError, InfiniteData, QueryClient, QueryKey } from "@tanstack/que
|
|
|
19
14
|
* `hasNextPage`, `hasPreviousPage`, `isFetchingNextPage`, and `isFetchingPreviousPage`. `data.pages` and
|
|
20
15
|
* `data.pageParams` are also added, as long as a `select` doesn't change `TData` away from its default
|
|
21
16
|
* `InfiniteData<TQueryFnData>` shape.
|
|
22
|
-
*
|
|
17
|
+
* @remarks Keep in mind that imperative fetch calls, such as `fetchNextPage`, may interfere with the default
|
|
18
|
+
* refetch behavior, resulting in outdated data. Make sure to call these functions only in response to user
|
|
19
|
+
* actions, or add conditions like `hasNextPage && !isFetching`.
|
|
20
|
+
* @see {@link infiniteQueryOptions} to share these options between `useInfiniteQuery` and imperative APIs like `queryClient.infiniteQuery`.
|
|
23
21
|
* @example
|
|
24
22
|
* ```tsx
|
|
25
23
|
* import { useInfiniteQuery } from '@tanstack/react-query'
|
|
@@ -50,11 +48,6 @@ export declare function useInfiniteQuery<TQueryFnData, TError = DefaultError, TD
|
|
|
50
48
|
/**
|
|
51
49
|
* The options for `useInfiniteQuery` are identical to `useQuery`, with the addition of
|
|
52
50
|
* `initialPageParam`, `getNextPageParam`, `getPreviousPageParam`, and `maxPages`.
|
|
53
|
-
*
|
|
54
|
-
* @remarks Keep in mind that imperative fetch calls, such as `fetchNextPage`, may interfere with the default
|
|
55
|
-
* refetch behavior, resulting in outdated data. Make sure to call these functions only in response to user
|
|
56
|
-
* actions, or add conditions like `hasNextPage && !isFetching`.
|
|
57
|
-
* @see {@link infiniteQueryOptions} to share these options between `useInfiniteQuery` and imperative APIs like `queryClient.infiniteQuery`.
|
|
58
51
|
* @param options - The {@link UndefinedInitialDataInfiniteOptions} to use — everything you can pass to `useInfiniteQuery`.
|
|
59
52
|
* @param queryClient - Use this to use a custom `QueryClient`. Otherwise, the one from the nearest context will
|
|
60
53
|
* be used.
|
|
@@ -62,7 +55,10 @@ export declare function useInfiniteQuery<TQueryFnData, TError = DefaultError, TD
|
|
|
62
55
|
* `hasNextPage`, `hasPreviousPage`, `isFetchingNextPage`, and `isFetchingPreviousPage`. `data.pages` and
|
|
63
56
|
* `data.pageParams` are also added, as long as a `select` doesn't change `TData` away from its default
|
|
64
57
|
* `InfiniteData<TQueryFnData>` shape.
|
|
65
|
-
*
|
|
58
|
+
* @remarks Keep in mind that imperative fetch calls, such as `fetchNextPage`, may interfere with the default
|
|
59
|
+
* refetch behavior, resulting in outdated data. Make sure to call these functions only in response to user
|
|
60
|
+
* actions, or add conditions like `hasNextPage && !isFetching`.
|
|
61
|
+
* @see {@link infiniteQueryOptions} to share these options between `useInfiniteQuery` and imperative APIs like `queryClient.infiniteQuery`.
|
|
66
62
|
* @example
|
|
67
63
|
* Fetching the next page from a "Load More" button click:
|
|
68
64
|
* ```tsx
|
|
@@ -101,7 +97,6 @@ export declare function useInfiniteQuery<TQueryFnData, TError = DefaultError, TD
|
|
|
101
97
|
* )
|
|
102
98
|
* }
|
|
103
99
|
* ```
|
|
104
|
-
*
|
|
105
100
|
* @example
|
|
106
101
|
* Fetching the next page automatically as the user scrolls, using an `IntersectionObserver` on a
|
|
107
102
|
* sentinel element after the list:
|
|
@@ -160,11 +155,6 @@ export declare function useInfiniteQuery<TQueryFnData, TError = DefaultError, TD
|
|
|
160
155
|
/**
|
|
161
156
|
* The options for `useInfiniteQuery` are identical to `useQuery`, with the addition of
|
|
162
157
|
* `initialPageParam`, `getNextPageParam`, `getPreviousPageParam`, and `maxPages`.
|
|
163
|
-
*
|
|
164
|
-
* @remarks Keep in mind that imperative fetch calls, such as `fetchNextPage`, may interfere with the default
|
|
165
|
-
* refetch behavior, resulting in outdated data. Make sure to call these functions only in response to user
|
|
166
|
-
* actions, or add conditions like `hasNextPage && !isFetching`.
|
|
167
|
-
* @see {@link infiniteQueryOptions} to share these options between `useInfiniteQuery` and imperative APIs like `queryClient.infiniteQuery`.
|
|
168
158
|
* @param options - The {@link UseInfiniteQueryOptions} to use — everything you can pass to `useInfiniteQuery`.
|
|
169
159
|
* @param queryClient - Use this to use a custom `QueryClient`. Otherwise, the one from the nearest context will
|
|
170
160
|
* be used.
|
|
@@ -172,7 +162,10 @@ export declare function useInfiniteQuery<TQueryFnData, TError = DefaultError, TD
|
|
|
172
162
|
* `hasNextPage`, `hasPreviousPage`, `isFetchingNextPage`, and `isFetchingPreviousPage`. `data.pages` and
|
|
173
163
|
* `data.pageParams` are also added, as long as a `select` doesn't change `TData` away from its default
|
|
174
164
|
* `InfiniteData<TQueryFnData>` shape.
|
|
175
|
-
*
|
|
165
|
+
* @remarks Keep in mind that imperative fetch calls, such as `fetchNextPage`, may interfere with the default
|
|
166
|
+
* refetch behavior, resulting in outdated data. Make sure to call these functions only in response to user
|
|
167
|
+
* actions, or add conditions like `hasNextPage && !isFetching`.
|
|
168
|
+
* @see {@link infiniteQueryOptions} to share these options between `useInfiniteQuery` and imperative APIs like `queryClient.infiniteQuery`.
|
|
176
169
|
* @example
|
|
177
170
|
* Fetching the next page from a "Load More" button click:
|
|
178
171
|
* ```tsx
|
|
@@ -211,7 +204,6 @@ export declare function useInfiniteQuery<TQueryFnData, TError = DefaultError, TD
|
|
|
211
204
|
* )
|
|
212
205
|
* }
|
|
213
206
|
* ```
|
|
214
|
-
*
|
|
215
207
|
* @example
|
|
216
208
|
* Fetching the next page automatically as the user scrolls, using an `IntersectionObserver` on a
|
|
217
209
|
* sentinel element after the list:
|
|
@@ -265,7 +257,6 @@ export declare function useInfiniteQuery<TQueryFnData, TError = DefaultError, TD
|
|
|
265
257
|
* )
|
|
266
258
|
* }
|
|
267
259
|
* ```
|
|
268
|
-
*
|
|
269
260
|
* @example
|
|
270
261
|
* A query that's disabled, type safe, until `postId` is set — pass `skipToken` as `queryFn`
|
|
271
262
|
* instead of setting `enabled: false`:
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useInfiniteQuery.d.cts","names":[],"sources":["../../src/useInfiniteQuery.ts"],"mappings":"
|
|
1
|
+
{"version":3,"file":"useInfiniteQuery.d.cts","names":[],"sources":["../../src/useInfiniteQuery.ts"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;wBA8DgB,iBACd,cACA,SAAS,cACT,QAAQ,aAAa,eACrB,kBAAkB,WAAW,UAC7B,sBAEA,SAAS,kCACP,cACA,QACA,OACA,WACA,aAEF,cAAc,cACb,8BAA8B,OAAO;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;wBA4GxB,iBACd,cACA,SAAS,cACT,QAAQ,aAAa,eACrB,kBAAkB,WAAW,UAC7B,sBAEA,SAAS,oCACP,cACA,QACA,OACA,WACA,aAEF,cAAc,cACb,uBAAuB,OAAO;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;wBAyIjB,iBACd,cACA,SAAS,cACT,QAAQ,aAAa,eACrB,kBAAkB,WAAW,UAC7B,sBAEA,SAAS,wBACP,cACA,QACA,OACA,WACA,aAEF,cAAc,cACb,uBAAuB,OAAO"}
|
|
@@ -7,11 +7,6 @@ import { DefaultError, InfiniteData, QueryClient, QueryKey } from "@tanstack/que
|
|
|
7
7
|
* `initialPageParam`, `getNextPageParam`, `getPreviousPageParam`, and `maxPages`.
|
|
8
8
|
*
|
|
9
9
|
* This overload is selected when `initialData` is set.
|
|
10
|
-
*
|
|
11
|
-
* @remarks Keep in mind that imperative fetch calls, such as `fetchNextPage`, may interfere with the default
|
|
12
|
-
* refetch behavior, resulting in outdated data. Make sure to call these functions only in response to user
|
|
13
|
-
* actions, or add conditions like `hasNextPage && !isFetching`.
|
|
14
|
-
* @see {@link infiniteQueryOptions} to share these options between `useInfiniteQuery` and imperative APIs like `queryClient.infiniteQuery`.
|
|
15
10
|
* @param options - The {@link DefinedInitialDataInfiniteOptions} to use — everything you can pass to `useInfiniteQuery`, with `initialData` set.
|
|
16
11
|
* @param queryClient - Use this to use a custom `QueryClient`. Otherwise, the one from the nearest context will
|
|
17
12
|
* be used.
|
|
@@ -19,7 +14,10 @@ import { DefaultError, InfiniteData, QueryClient, QueryKey } from "@tanstack/que
|
|
|
19
14
|
* `hasNextPage`, `hasPreviousPage`, `isFetchingNextPage`, and `isFetchingPreviousPage`. `data.pages` and
|
|
20
15
|
* `data.pageParams` are also added, as long as a `select` doesn't change `TData` away from its default
|
|
21
16
|
* `InfiniteData<TQueryFnData>` shape.
|
|
22
|
-
*
|
|
17
|
+
* @remarks Keep in mind that imperative fetch calls, such as `fetchNextPage`, may interfere with the default
|
|
18
|
+
* refetch behavior, resulting in outdated data. Make sure to call these functions only in response to user
|
|
19
|
+
* actions, or add conditions like `hasNextPage && !isFetching`.
|
|
20
|
+
* @see {@link infiniteQueryOptions} to share these options between `useInfiniteQuery` and imperative APIs like `queryClient.infiniteQuery`.
|
|
23
21
|
* @example
|
|
24
22
|
* ```tsx
|
|
25
23
|
* import { useInfiniteQuery } from '@tanstack/react-query'
|
|
@@ -50,11 +48,6 @@ export declare function useInfiniteQuery<TQueryFnData, TError = DefaultError, TD
|
|
|
50
48
|
/**
|
|
51
49
|
* The options for `useInfiniteQuery` are identical to `useQuery`, with the addition of
|
|
52
50
|
* `initialPageParam`, `getNextPageParam`, `getPreviousPageParam`, and `maxPages`.
|
|
53
|
-
*
|
|
54
|
-
* @remarks Keep in mind that imperative fetch calls, such as `fetchNextPage`, may interfere with the default
|
|
55
|
-
* refetch behavior, resulting in outdated data. Make sure to call these functions only in response to user
|
|
56
|
-
* actions, or add conditions like `hasNextPage && !isFetching`.
|
|
57
|
-
* @see {@link infiniteQueryOptions} to share these options between `useInfiniteQuery` and imperative APIs like `queryClient.infiniteQuery`.
|
|
58
51
|
* @param options - The {@link UndefinedInitialDataInfiniteOptions} to use — everything you can pass to `useInfiniteQuery`.
|
|
59
52
|
* @param queryClient - Use this to use a custom `QueryClient`. Otherwise, the one from the nearest context will
|
|
60
53
|
* be used.
|
|
@@ -62,7 +55,10 @@ export declare function useInfiniteQuery<TQueryFnData, TError = DefaultError, TD
|
|
|
62
55
|
* `hasNextPage`, `hasPreviousPage`, `isFetchingNextPage`, and `isFetchingPreviousPage`. `data.pages` and
|
|
63
56
|
* `data.pageParams` are also added, as long as a `select` doesn't change `TData` away from its default
|
|
64
57
|
* `InfiniteData<TQueryFnData>` shape.
|
|
65
|
-
*
|
|
58
|
+
* @remarks Keep in mind that imperative fetch calls, such as `fetchNextPage`, may interfere with the default
|
|
59
|
+
* refetch behavior, resulting in outdated data. Make sure to call these functions only in response to user
|
|
60
|
+
* actions, or add conditions like `hasNextPage && !isFetching`.
|
|
61
|
+
* @see {@link infiniteQueryOptions} to share these options between `useInfiniteQuery` and imperative APIs like `queryClient.infiniteQuery`.
|
|
66
62
|
* @example
|
|
67
63
|
* Fetching the next page from a "Load More" button click:
|
|
68
64
|
* ```tsx
|
|
@@ -101,7 +97,6 @@ export declare function useInfiniteQuery<TQueryFnData, TError = DefaultError, TD
|
|
|
101
97
|
* )
|
|
102
98
|
* }
|
|
103
99
|
* ```
|
|
104
|
-
*
|
|
105
100
|
* @example
|
|
106
101
|
* Fetching the next page automatically as the user scrolls, using an `IntersectionObserver` on a
|
|
107
102
|
* sentinel element after the list:
|
|
@@ -160,11 +155,6 @@ export declare function useInfiniteQuery<TQueryFnData, TError = DefaultError, TD
|
|
|
160
155
|
/**
|
|
161
156
|
* The options for `useInfiniteQuery` are identical to `useQuery`, with the addition of
|
|
162
157
|
* `initialPageParam`, `getNextPageParam`, `getPreviousPageParam`, and `maxPages`.
|
|
163
|
-
*
|
|
164
|
-
* @remarks Keep in mind that imperative fetch calls, such as `fetchNextPage`, may interfere with the default
|
|
165
|
-
* refetch behavior, resulting in outdated data. Make sure to call these functions only in response to user
|
|
166
|
-
* actions, or add conditions like `hasNextPage && !isFetching`.
|
|
167
|
-
* @see {@link infiniteQueryOptions} to share these options between `useInfiniteQuery` and imperative APIs like `queryClient.infiniteQuery`.
|
|
168
158
|
* @param options - The {@link UseInfiniteQueryOptions} to use — everything you can pass to `useInfiniteQuery`.
|
|
169
159
|
* @param queryClient - Use this to use a custom `QueryClient`. Otherwise, the one from the nearest context will
|
|
170
160
|
* be used.
|
|
@@ -172,7 +162,10 @@ export declare function useInfiniteQuery<TQueryFnData, TError = DefaultError, TD
|
|
|
172
162
|
* `hasNextPage`, `hasPreviousPage`, `isFetchingNextPage`, and `isFetchingPreviousPage`. `data.pages` and
|
|
173
163
|
* `data.pageParams` are also added, as long as a `select` doesn't change `TData` away from its default
|
|
174
164
|
* `InfiniteData<TQueryFnData>` shape.
|
|
175
|
-
*
|
|
165
|
+
* @remarks Keep in mind that imperative fetch calls, such as `fetchNextPage`, may interfere with the default
|
|
166
|
+
* refetch behavior, resulting in outdated data. Make sure to call these functions only in response to user
|
|
167
|
+
* actions, or add conditions like `hasNextPage && !isFetching`.
|
|
168
|
+
* @see {@link infiniteQueryOptions} to share these options between `useInfiniteQuery` and imperative APIs like `queryClient.infiniteQuery`.
|
|
176
169
|
* @example
|
|
177
170
|
* Fetching the next page from a "Load More" button click:
|
|
178
171
|
* ```tsx
|
|
@@ -211,7 +204,6 @@ export declare function useInfiniteQuery<TQueryFnData, TError = DefaultError, TD
|
|
|
211
204
|
* )
|
|
212
205
|
* }
|
|
213
206
|
* ```
|
|
214
|
-
*
|
|
215
207
|
* @example
|
|
216
208
|
* Fetching the next page automatically as the user scrolls, using an `IntersectionObserver` on a
|
|
217
209
|
* sentinel element after the list:
|
|
@@ -265,7 +257,6 @@ export declare function useInfiniteQuery<TQueryFnData, TError = DefaultError, TD
|
|
|
265
257
|
* )
|
|
266
258
|
* }
|
|
267
259
|
* ```
|
|
268
|
-
*
|
|
269
260
|
* @example
|
|
270
261
|
* A query that's disabled, type safe, until `postId` is set — pass `skipToken` as `queryFn`
|
|
271
262
|
* instead of setting `enabled: false`:
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useInfiniteQuery.d.ts","names":[],"sources":["../../src/useInfiniteQuery.ts"],"mappings":"
|
|
1
|
+
{"version":3,"file":"useInfiniteQuery.d.ts","names":[],"sources":["../../src/useInfiniteQuery.ts"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;wBA8DgB,iBACd,cACA,SAAS,cACT,QAAQ,aAAa,eACrB,kBAAkB,WAAW,UAC7B,sBAEA,SAAS,kCACP,cACA,QACA,OACA,WACA,aAEF,cAAc,cACb,8BAA8B,OAAO;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;wBA4GxB,iBACd,cACA,SAAS,cACT,QAAQ,aAAa,eACrB,kBAAkB,WAAW,UAC7B,sBAEA,SAAS,oCACP,cACA,QACA,OACA,WACA,aAEF,cAAc,cACb,uBAAuB,OAAO;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;wBAyIjB,iBACd,cACA,SAAS,cACT,QAAQ,aAAa,eACrB,kBAAkB,WAAW,UAC7B,sBAEA,SAAS,wBACP,cACA,QACA,OACA,WACA,aAEF,cAAc,cACb,uBAAuB,OAAO"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useInfiniteQuery.js","names":[],"sources":["../../src/useInfiniteQuery.ts"],"sourcesContent":["'use client'\nimport { InfiniteQueryObserver } from '@tanstack/query-core'\nimport { useBaseQuery } from './useBaseQuery'\nimport type {\n DefaultError,\n InfiniteData,\n QueryClient,\n QueryKey,\n QueryObserver,\n} from '@tanstack/query-core'\nimport type {\n DefinedUseInfiniteQueryResult,\n UseInfiniteQueryOptions,\n UseInfiniteQueryResult,\n} from './types'\nimport type {\n DefinedInitialDataInfiniteOptions,\n UndefinedInitialDataInfiniteOptions,\n} from './infiniteQueryOptions'\n\n/**\n * The options for `useInfiniteQuery` are identical to `useQuery`, with the addition of\n * `initialPageParam`, `getNextPageParam`, `getPreviousPageParam`, and `maxPages`.\n *\n * This overload is selected when `initialData` is set.\n *\n * @remarks Keep in mind that imperative fetch calls, such as `fetchNextPage`, may interfere with the default\n * refetch behavior, resulting in outdated data. Make sure to call these functions only in response to user\n * actions, or add conditions like `hasNextPage && !isFetching`.\n * @see {@link infiniteQueryOptions} to share these options between `useInfiniteQuery` and imperative APIs like `queryClient.infiniteQuery`.\n * @param options - The {@link DefinedInitialDataInfiniteOptions} to use — everything you can pass to `useInfiniteQuery`, with `initialData` set.\n * @param queryClient - Use this to use a custom `QueryClient`. Otherwise, the one from the nearest context will\n * be used.\n * @returns The same properties as `useQuery`, with the addition of `fetchNextPage`, `fetchPreviousPage`,\n * `hasNextPage`, `hasPreviousPage`, `isFetchingNextPage`, and `isFetchingPreviousPage`. `data.pages` and\n * `data.pageParams` are also added, as long as a `select` doesn't change `TData` away from its default\n * `InfiniteData<TQueryFnData>` shape.\n *\n * @example\n * ```tsx\n * import { useInfiniteQuery } from '@tanstack/react-query'\n *\n * function Projects() {\n * // `data` is never `undefined`, thanks to `initialData` — even if a refetch fails, so the\n * // list stays visible alongside the error.\n * const { data, isError, error } = useInfiniteQuery({\n * queryKey: ['projects'],\n * queryFn: ({ pageParam }) => fetchProjects(pageParam),\n * initialPageParam: 0,\n * getNextPageParam: (lastPage) => lastPage.nextId,\n * initialData: { pages: [], pageParams: [] },\n * })\n *\n * return (\n * <div>\n * {isError ? <span>Error: {error.message}</span> : null}\n * <ul>\n * {data.pages.map((page) => page.projects.map((p) => <li key={p.id}>{p.name}</li>))}\n * </ul>\n * </div>\n * )\n * }\n * ```\n */\nexport function useInfiniteQuery<\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 queryClient?: QueryClient,\n): DefinedUseInfiniteQueryResult<TData, TError>\n\n/**\n * The options for `useInfiniteQuery` are identical to `useQuery`, with the addition of\n * `initialPageParam`, `getNextPageParam`, `getPreviousPageParam`, and `maxPages`.\n *\n * @remarks Keep in mind that imperative fetch calls, such as `fetchNextPage`, may interfere with the default\n * refetch behavior, resulting in outdated data. Make sure to call these functions only in response to user\n * actions, or add conditions like `hasNextPage && !isFetching`.\n * @see {@link infiniteQueryOptions} to share these options between `useInfiniteQuery` and imperative APIs like `queryClient.infiniteQuery`.\n * @param options - The {@link UndefinedInitialDataInfiniteOptions} to use — everything you can pass to `useInfiniteQuery`.\n * @param queryClient - Use this to use a custom `QueryClient`. Otherwise, the one from the nearest context will\n * be used.\n * @returns The same properties as `useQuery`, with the addition of `fetchNextPage`, `fetchPreviousPage`,\n * `hasNextPage`, `hasPreviousPage`, `isFetchingNextPage`, and `isFetchingPreviousPage`. `data.pages` and\n * `data.pageParams` are also added, as long as a `select` doesn't change `TData` away from its default\n * `InfiniteData<TQueryFnData>` shape.\n *\n * @example\n * Fetching the next page from a \"Load More\" button click:\n * ```tsx\n * import { useInfiniteQuery } from '@tanstack/react-query'\n *\n * function Projects() {\n * const { data, isPending, isError, error, fetchNextPage, hasNextPage, isFetching, isFetchingNextPage } =\n * useInfiniteQuery({\n * queryKey: ['projects'],\n * queryFn: ({ pageParam }) => fetchProjects(pageParam),\n * initialPageParam: 0,\n * getNextPageParam: (lastPage) => lastPage.nextId,\n * })\n *\n * if (isPending) return 'Loading...'\n * if (isError) return <span>Error: {error.message}</span>\n *\n * return (\n * <>\n * <ul>\n * {data.pages.map((page) =>\n * page.projects.map((project) => <li key={project.id}>{project.name}</li>),\n * )}\n * </ul>\n * <button\n * onClick={() => fetchNextPage()}\n * disabled={!hasNextPage || isFetching}\n * >\n * {isFetchingNextPage\n * ? 'Loading more...'\n * : hasNextPage\n * ? 'Load More'\n * : 'Nothing more to load'}\n * </button>\n * </>\n * )\n * }\n * ```\n *\n * @example\n * Fetching the next page automatically as the user scrolls, using an `IntersectionObserver` on a\n * sentinel element after the list:\n * ```tsx\n * import { useInfiniteQuery } from '@tanstack/react-query'\n * import { useEffect, useRef } from 'react'\n *\n * function Projects() {\n * const {\n * data,\n * isPending,\n * isError,\n * error,\n * fetchNextPage,\n * hasNextPage,\n * isFetching,\n * isFetchingNextPage,\n * } = useInfiniteQuery({\n * queryKey: ['projects'],\n * queryFn: ({ pageParam }) => fetchProjects(pageParam),\n * initialPageParam: 0,\n * getNextPageParam: (lastPage) => lastPage.nextId,\n * })\n *\n * const sentinelRef = useRef<HTMLDivElement>(null)\n *\n * useEffect(() => {\n * const sentinel = sentinelRef.current\n * if (sentinel == null || !hasNextPage || isFetching) return\n *\n * const observer = new IntersectionObserver(([entry]) => {\n * if (entry?.isIntersecting) fetchNextPage()\n * })\n * observer.observe(sentinel)\n *\n * return () => observer.disconnect()\n * }, [hasNextPage, isFetching, fetchNextPage])\n *\n * if (isPending) return 'Loading...'\n * if (isError) return <span>Error: {error.message}</span>\n *\n * return (\n * <>\n * <ul>\n * {data.pages.map((page) =>\n * page.projects.map((project) => <li key={project.id}>{project.name}</li>),\n * )}\n * </ul>\n * <div ref={sentinelRef}>{isFetchingNextPage ? 'Loading more...' : null}</div>\n * </>\n * )\n * }\n * ```\n */\nexport function useInfiniteQuery<\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 queryClient?: QueryClient,\n): UseInfiniteQueryResult<TData, TError>\n\n/**\n * The options for `useInfiniteQuery` are identical to `useQuery`, with the addition of\n * `initialPageParam`, `getNextPageParam`, `getPreviousPageParam`, and `maxPages`.\n *\n * @remarks Keep in mind that imperative fetch calls, such as `fetchNextPage`, may interfere with the default\n * refetch behavior, resulting in outdated data. Make sure to call these functions only in response to user\n * actions, or add conditions like `hasNextPage && !isFetching`.\n * @see {@link infiniteQueryOptions} to share these options between `useInfiniteQuery` and imperative APIs like `queryClient.infiniteQuery`.\n * @param options - The {@link UseInfiniteQueryOptions} to use — everything you can pass to `useInfiniteQuery`.\n * @param queryClient - Use this to use a custom `QueryClient`. Otherwise, the one from the nearest context will\n * be used.\n * @returns The same properties as `useQuery`, with the addition of `fetchNextPage`, `fetchPreviousPage`,\n * `hasNextPage`, `hasPreviousPage`, `isFetchingNextPage`, and `isFetchingPreviousPage`. `data.pages` and\n * `data.pageParams` are also added, as long as a `select` doesn't change `TData` away from its default\n * `InfiniteData<TQueryFnData>` shape.\n *\n * @example\n * Fetching the next page from a \"Load More\" button click:\n * ```tsx\n * import { useInfiniteQuery } from '@tanstack/react-query'\n *\n * function Projects() {\n * const { data, isPending, isError, error, fetchNextPage, hasNextPage, isFetching, isFetchingNextPage } =\n * useInfiniteQuery({\n * queryKey: ['projects'],\n * queryFn: ({ pageParam }) => fetchProjects(pageParam),\n * initialPageParam: 0,\n * getNextPageParam: (lastPage) => lastPage.nextId,\n * })\n *\n * if (isPending) return 'Loading...'\n * if (isError) return <span>Error: {error.message}</span>\n *\n * return (\n * <>\n * <ul>\n * {data.pages.map((page) =>\n * page.projects.map((project) => <li key={project.id}>{project.name}</li>),\n * )}\n * </ul>\n * <button\n * onClick={() => fetchNextPage()}\n * disabled={!hasNextPage || isFetching}\n * >\n * {isFetchingNextPage\n * ? 'Loading more...'\n * : hasNextPage\n * ? 'Load More'\n * : 'Nothing more to load'}\n * </button>\n * </>\n * )\n * }\n * ```\n *\n * @example\n * Fetching the next page automatically as the user scrolls, using an `IntersectionObserver` on a\n * sentinel element after the list:\n * ```tsx\n * import { useInfiniteQuery } from '@tanstack/react-query'\n * import { useEffect, useRef } from 'react'\n *\n * function Projects() {\n * const {\n * data,\n * isPending,\n * isError,\n * error,\n * fetchNextPage,\n * hasNextPage,\n * isFetching,\n * isFetchingNextPage,\n * } = useInfiniteQuery({\n * queryKey: ['projects'],\n * queryFn: ({ pageParam }) => fetchProjects(pageParam),\n * initialPageParam: 0,\n * getNextPageParam: (lastPage) => lastPage.nextId,\n * })\n *\n * const sentinelRef = useRef<HTMLDivElement>(null)\n *\n * useEffect(() => {\n * const sentinel = sentinelRef.current\n * if (sentinel == null || !hasNextPage || isFetching) return\n *\n * const observer = new IntersectionObserver(([entry]) => {\n * if (entry?.isIntersecting) fetchNextPage()\n * })\n * observer.observe(sentinel)\n *\n * return () => observer.disconnect()\n * }, [hasNextPage, isFetching, fetchNextPage])\n *\n * if (isPending) return 'Loading...'\n * if (isError) return <span>Error: {error.message}</span>\n *\n * return (\n * <>\n * <ul>\n * {data.pages.map((page) =>\n * page.projects.map((project) => <li key={project.id}>{project.name}</li>),\n * )}\n * </ul>\n * <div ref={sentinelRef}>{isFetchingNextPage ? 'Loading more...' : null}</div>\n * </>\n * )\n * }\n * ```\n *\n * @example\n * A query that's disabled, type safe, until `postId` is set — pass `skipToken` as `queryFn`\n * instead of setting `enabled: false`:\n * ```tsx\n * import { skipToken, useInfiniteQuery } from '@tanstack/react-query'\n *\n * function Comments({ postId }: { postId: string | undefined }) {\n * // Use `isLoading`, not `isPending`, so the loading state doesn't show while the query is disabled.\n * const { data, isLoading, isError, error } = useInfiniteQuery({\n * queryKey: ['post', postId, 'comments'],\n * queryFn:\n * postId != null\n * ? ({ pageParam }) => fetchComments(postId, pageParam)\n * : skipToken,\n * initialPageParam: 0,\n * getNextPageParam: (lastPage) => lastPage.nextId,\n * })\n *\n * if (postId == null) return 'Select a post'\n * if (isLoading) return 'Loading...'\n * if (isError) return <span>Error: {error.message}</span>\n *\n * return (\n * <ul>\n * {data?.pages.map((page) => page.comments.map((c) => <li key={c.id}>{c.text}</li>))}\n * </ul>\n * )\n * }\n * ```\n */\nexport function useInfiniteQuery<\n TQueryFnData,\n TError = DefaultError,\n TData = InfiniteData<TQueryFnData>,\n TQueryKey extends QueryKey = QueryKey,\n TPageParam = unknown,\n>(\n options: UseInfiniteQueryOptions<\n TQueryFnData,\n TError,\n TData,\n TQueryKey,\n TPageParam\n >,\n queryClient?: QueryClient,\n): UseInfiniteQueryResult<TData, TError>\n\nexport function useInfiniteQuery(\n options: UseInfiniteQueryOptions,\n queryClient?: QueryClient,\n) {\n return useBaseQuery(\n options,\n InfiniteQueryObserver as typeof QueryObserver,\n queryClient,\n )\n}\n"],"mappings":";;;;AA2WA,SAAgB,iBACd,SACA,aACA;CACA,OAAO,aACL,SACA,uBACA,WACF;AACF"}
|
|
1
|
+
{"version":3,"file":"useInfiniteQuery.js","names":[],"sources":["../../src/useInfiniteQuery.ts"],"sourcesContent":["'use client'\nimport { InfiniteQueryObserver } from '@tanstack/query-core'\nimport { useBaseQuery } from './useBaseQuery'\nimport type {\n DefaultError,\n InfiniteData,\n QueryClient,\n QueryKey,\n QueryObserver,\n} from '@tanstack/query-core'\nimport type {\n DefinedUseInfiniteQueryResult,\n UseInfiniteQueryOptions,\n UseInfiniteQueryResult,\n} from './types'\nimport type {\n DefinedInitialDataInfiniteOptions,\n UndefinedInitialDataInfiniteOptions,\n} from './infiniteQueryOptions'\n\n/**\n * The options for `useInfiniteQuery` are identical to `useQuery`, with the addition of\n * `initialPageParam`, `getNextPageParam`, `getPreviousPageParam`, and `maxPages`.\n *\n * This overload is selected when `initialData` is set.\n * @param options - The {@link DefinedInitialDataInfiniteOptions} to use — everything you can pass to `useInfiniteQuery`, with `initialData` set.\n * @param queryClient - Use this to use a custom `QueryClient`. Otherwise, the one from the nearest context will\n * be used.\n * @returns The same properties as `useQuery`, with the addition of `fetchNextPage`, `fetchPreviousPage`,\n * `hasNextPage`, `hasPreviousPage`, `isFetchingNextPage`, and `isFetchingPreviousPage`. `data.pages` and\n * `data.pageParams` are also added, as long as a `select` doesn't change `TData` away from its default\n * `InfiniteData<TQueryFnData>` shape.\n * @remarks Keep in mind that imperative fetch calls, such as `fetchNextPage`, may interfere with the default\n * refetch behavior, resulting in outdated data. Make sure to call these functions only in response to user\n * actions, or add conditions like `hasNextPage && !isFetching`.\n * @see {@link infiniteQueryOptions} to share these options between `useInfiniteQuery` and imperative APIs like `queryClient.infiniteQuery`.\n * @example\n * ```tsx\n * import { useInfiniteQuery } from '@tanstack/react-query'\n *\n * function Projects() {\n * // `data` is never `undefined`, thanks to `initialData` — even if a refetch fails, so the\n * // list stays visible alongside the error.\n * const { data, isError, error } = useInfiniteQuery({\n * queryKey: ['projects'],\n * queryFn: ({ pageParam }) => fetchProjects(pageParam),\n * initialPageParam: 0,\n * getNextPageParam: (lastPage) => lastPage.nextId,\n * initialData: { pages: [], pageParams: [] },\n * })\n *\n * return (\n * <div>\n * {isError ? <span>Error: {error.message}</span> : null}\n * <ul>\n * {data.pages.map((page) => page.projects.map((p) => <li key={p.id}>{p.name}</li>))}\n * </ul>\n * </div>\n * )\n * }\n * ```\n */\nexport function useInfiniteQuery<\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 queryClient?: QueryClient,\n): DefinedUseInfiniteQueryResult<TData, TError>\n\n/**\n * The options for `useInfiniteQuery` are identical to `useQuery`, with the addition of\n * `initialPageParam`, `getNextPageParam`, `getPreviousPageParam`, and `maxPages`.\n * @param options - The {@link UndefinedInitialDataInfiniteOptions} to use — everything you can pass to `useInfiniteQuery`.\n * @param queryClient - Use this to use a custom `QueryClient`. Otherwise, the one from the nearest context will\n * be used.\n * @returns The same properties as `useQuery`, with the addition of `fetchNextPage`, `fetchPreviousPage`,\n * `hasNextPage`, `hasPreviousPage`, `isFetchingNextPage`, and `isFetchingPreviousPage`. `data.pages` and\n * `data.pageParams` are also added, as long as a `select` doesn't change `TData` away from its default\n * `InfiniteData<TQueryFnData>` shape.\n * @remarks Keep in mind that imperative fetch calls, such as `fetchNextPage`, may interfere with the default\n * refetch behavior, resulting in outdated data. Make sure to call these functions only in response to user\n * actions, or add conditions like `hasNextPage && !isFetching`.\n * @see {@link infiniteQueryOptions} to share these options between `useInfiniteQuery` and imperative APIs like `queryClient.infiniteQuery`.\n * @example\n * Fetching the next page from a \"Load More\" button click:\n * ```tsx\n * import { useInfiniteQuery } from '@tanstack/react-query'\n *\n * function Projects() {\n * const { data, isPending, isError, error, fetchNextPage, hasNextPage, isFetching, isFetchingNextPage } =\n * useInfiniteQuery({\n * queryKey: ['projects'],\n * queryFn: ({ pageParam }) => fetchProjects(pageParam),\n * initialPageParam: 0,\n * getNextPageParam: (lastPage) => lastPage.nextId,\n * })\n *\n * if (isPending) return 'Loading...'\n * if (isError) return <span>Error: {error.message}</span>\n *\n * return (\n * <>\n * <ul>\n * {data.pages.map((page) =>\n * page.projects.map((project) => <li key={project.id}>{project.name}</li>),\n * )}\n * </ul>\n * <button\n * onClick={() => fetchNextPage()}\n * disabled={!hasNextPage || isFetching}\n * >\n * {isFetchingNextPage\n * ? 'Loading more...'\n * : hasNextPage\n * ? 'Load More'\n * : 'Nothing more to load'}\n * </button>\n * </>\n * )\n * }\n * ```\n * @example\n * Fetching the next page automatically as the user scrolls, using an `IntersectionObserver` on a\n * sentinel element after the list:\n * ```tsx\n * import { useInfiniteQuery } from '@tanstack/react-query'\n * import { useEffect, useRef } from 'react'\n *\n * function Projects() {\n * const {\n * data,\n * isPending,\n * isError,\n * error,\n * fetchNextPage,\n * hasNextPage,\n * isFetching,\n * isFetchingNextPage,\n * } = useInfiniteQuery({\n * queryKey: ['projects'],\n * queryFn: ({ pageParam }) => fetchProjects(pageParam),\n * initialPageParam: 0,\n * getNextPageParam: (lastPage) => lastPage.nextId,\n * })\n *\n * const sentinelRef = useRef<HTMLDivElement>(null)\n *\n * useEffect(() => {\n * const sentinel = sentinelRef.current\n * if (sentinel == null || !hasNextPage || isFetching) return\n *\n * const observer = new IntersectionObserver(([entry]) => {\n * if (entry?.isIntersecting) fetchNextPage()\n * })\n * observer.observe(sentinel)\n *\n * return () => observer.disconnect()\n * }, [hasNextPage, isFetching, fetchNextPage])\n *\n * if (isPending) return 'Loading...'\n * if (isError) return <span>Error: {error.message}</span>\n *\n * return (\n * <>\n * <ul>\n * {data.pages.map((page) =>\n * page.projects.map((project) => <li key={project.id}>{project.name}</li>),\n * )}\n * </ul>\n * <div ref={sentinelRef}>{isFetchingNextPage ? 'Loading more...' : null}</div>\n * </>\n * )\n * }\n * ```\n */\nexport function useInfiniteQuery<\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 queryClient?: QueryClient,\n): UseInfiniteQueryResult<TData, TError>\n\n/**\n * The options for `useInfiniteQuery` are identical to `useQuery`, with the addition of\n * `initialPageParam`, `getNextPageParam`, `getPreviousPageParam`, and `maxPages`.\n * @param options - The {@link UseInfiniteQueryOptions} to use — everything you can pass to `useInfiniteQuery`.\n * @param queryClient - Use this to use a custom `QueryClient`. Otherwise, the one from the nearest context will\n * be used.\n * @returns The same properties as `useQuery`, with the addition of `fetchNextPage`, `fetchPreviousPage`,\n * `hasNextPage`, `hasPreviousPage`, `isFetchingNextPage`, and `isFetchingPreviousPage`. `data.pages` and\n * `data.pageParams` are also added, as long as a `select` doesn't change `TData` away from its default\n * `InfiniteData<TQueryFnData>` shape.\n * @remarks Keep in mind that imperative fetch calls, such as `fetchNextPage`, may interfere with the default\n * refetch behavior, resulting in outdated data. Make sure to call these functions only in response to user\n * actions, or add conditions like `hasNextPage && !isFetching`.\n * @see {@link infiniteQueryOptions} to share these options between `useInfiniteQuery` and imperative APIs like `queryClient.infiniteQuery`.\n * @example\n * Fetching the next page from a \"Load More\" button click:\n * ```tsx\n * import { useInfiniteQuery } from '@tanstack/react-query'\n *\n * function Projects() {\n * const { data, isPending, isError, error, fetchNextPage, hasNextPage, isFetching, isFetchingNextPage } =\n * useInfiniteQuery({\n * queryKey: ['projects'],\n * queryFn: ({ pageParam }) => fetchProjects(pageParam),\n * initialPageParam: 0,\n * getNextPageParam: (lastPage) => lastPage.nextId,\n * })\n *\n * if (isPending) return 'Loading...'\n * if (isError) return <span>Error: {error.message}</span>\n *\n * return (\n * <>\n * <ul>\n * {data.pages.map((page) =>\n * page.projects.map((project) => <li key={project.id}>{project.name}</li>),\n * )}\n * </ul>\n * <button\n * onClick={() => fetchNextPage()}\n * disabled={!hasNextPage || isFetching}\n * >\n * {isFetchingNextPage\n * ? 'Loading more...'\n * : hasNextPage\n * ? 'Load More'\n * : 'Nothing more to load'}\n * </button>\n * </>\n * )\n * }\n * ```\n * @example\n * Fetching the next page automatically as the user scrolls, using an `IntersectionObserver` on a\n * sentinel element after the list:\n * ```tsx\n * import { useInfiniteQuery } from '@tanstack/react-query'\n * import { useEffect, useRef } from 'react'\n *\n * function Projects() {\n * const {\n * data,\n * isPending,\n * isError,\n * error,\n * fetchNextPage,\n * hasNextPage,\n * isFetching,\n * isFetchingNextPage,\n * } = useInfiniteQuery({\n * queryKey: ['projects'],\n * queryFn: ({ pageParam }) => fetchProjects(pageParam),\n * initialPageParam: 0,\n * getNextPageParam: (lastPage) => lastPage.nextId,\n * })\n *\n * const sentinelRef = useRef<HTMLDivElement>(null)\n *\n * useEffect(() => {\n * const sentinel = sentinelRef.current\n * if (sentinel == null || !hasNextPage || isFetching) return\n *\n * const observer = new IntersectionObserver(([entry]) => {\n * if (entry?.isIntersecting) fetchNextPage()\n * })\n * observer.observe(sentinel)\n *\n * return () => observer.disconnect()\n * }, [hasNextPage, isFetching, fetchNextPage])\n *\n * if (isPending) return 'Loading...'\n * if (isError) return <span>Error: {error.message}</span>\n *\n * return (\n * <>\n * <ul>\n * {data.pages.map((page) =>\n * page.projects.map((project) => <li key={project.id}>{project.name}</li>),\n * )}\n * </ul>\n * <div ref={sentinelRef}>{isFetchingNextPage ? 'Loading more...' : null}</div>\n * </>\n * )\n * }\n * ```\n * @example\n * A query that's disabled, type safe, until `postId` is set — pass `skipToken` as `queryFn`\n * instead of setting `enabled: false`:\n * ```tsx\n * import { skipToken, useInfiniteQuery } from '@tanstack/react-query'\n *\n * function Comments({ postId }: { postId: string | undefined }) {\n * // Use `isLoading`, not `isPending`, so the loading state doesn't show while the query is disabled.\n * const { data, isLoading, isError, error } = useInfiniteQuery({\n * queryKey: ['post', postId, 'comments'],\n * queryFn:\n * postId != null\n * ? ({ pageParam }) => fetchComments(postId, pageParam)\n * : skipToken,\n * initialPageParam: 0,\n * getNextPageParam: (lastPage) => lastPage.nextId,\n * })\n *\n * if (postId == null) return 'Select a post'\n * if (isLoading) return 'Loading...'\n * if (isError) return <span>Error: {error.message}</span>\n *\n * return (\n * <ul>\n * {data?.pages.map((page) => page.comments.map((c) => <li key={c.id}>{c.text}</li>))}\n * </ul>\n * )\n * }\n * ```\n */\nexport function useInfiniteQuery<\n TQueryFnData,\n TError = DefaultError,\n TData = InfiniteData<TQueryFnData>,\n TQueryKey extends QueryKey = QueryKey,\n TPageParam = unknown,\n>(\n options: UseInfiniteQueryOptions<\n TQueryFnData,\n TError,\n TData,\n TQueryKey,\n TPageParam\n >,\n queryClient?: QueryClient,\n): UseInfiniteQueryResult<TData, TError>\n\nexport function useInfiniteQuery(\n options: UseInfiniteQueryOptions,\n queryClient?: QueryClient,\n) {\n return useBaseQuery(\n options,\n InfiniteQueryObserver as typeof QueryObserver,\n queryClient,\n )\n}\n"],"mappings":";;;;AAkWA,SAAgB,iBACd,SACA,aACA;CACA,OAAO,aACL,SACA,uBACA,WACF;AACF"}
|
|
@@ -9,13 +9,11 @@ let _tanstack_query_core = require("@tanstack/query-core");
|
|
|
9
9
|
/**
|
|
10
10
|
* The `useIsFetching` hook returns the `number` of the queries that your application is loading or fetching in
|
|
11
11
|
* the background (useful for app-wide loading indicators).
|
|
12
|
-
*
|
|
13
12
|
* @param filters - The {@link QueryFilters} to narrow down the matched queries.
|
|
14
13
|
* @param queryClient - Use this to use a custom `QueryClient`. Otherwise, the one from the nearest context will
|
|
15
14
|
* be used.
|
|
16
15
|
* @returns Will be the `number` of the queries that your application is currently loading or fetching in the
|
|
17
16
|
* background.
|
|
18
|
-
*
|
|
19
17
|
* @example
|
|
20
18
|
* ```tsx
|
|
21
19
|
* import { useIsFetching } from '@tanstack/react-query'
|
|
@@ -27,7 +25,6 @@ let _tanstack_query_core = require("@tanstack/query-core");
|
|
|
27
25
|
* return isFetchingPosts ? <span>Refreshing posts...</span> : null
|
|
28
26
|
* }
|
|
29
27
|
* ```
|
|
30
|
-
*
|
|
31
28
|
* @example
|
|
32
29
|
* A global loading indicator for any query fetching in the background, not just the ones on screen:
|
|
33
30
|
* ```tsx
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useIsFetching.cjs","names":["useQueryClient","React","notifyManager"],"sources":["../../src/useIsFetching.ts"],"sourcesContent":["'use client'\nimport * as React from 'react'\nimport { notifyManager } from '@tanstack/query-core'\n\nimport { useQueryClient } from './QueryClientProvider'\nimport type { QueryClient, QueryFilters } from '@tanstack/query-core'\n\n/**\n * The `useIsFetching` hook returns the `number` of the queries that your application is loading or fetching in\n * the background (useful for app-wide loading indicators).\n
|
|
1
|
+
{"version":3,"file":"useIsFetching.cjs","names":["useQueryClient","React","notifyManager"],"sources":["../../src/useIsFetching.ts"],"sourcesContent":["'use client'\nimport * as React from 'react'\nimport { notifyManager } from '@tanstack/query-core'\n\nimport { useQueryClient } from './QueryClientProvider'\nimport type { QueryClient, QueryFilters } from '@tanstack/query-core'\n\n/**\n * The `useIsFetching` hook returns the `number` of the queries that your application is loading or fetching in\n * the background (useful for app-wide loading indicators).\n * @param filters - The {@link QueryFilters} to narrow down the matched queries.\n * @param queryClient - Use this to use a custom `QueryClient`. Otherwise, the one from the nearest context will\n * be used.\n * @returns Will be the `number` of the queries that your application is currently loading or fetching in the\n * background.\n * @example\n * ```tsx\n * import { useIsFetching } from '@tanstack/react-query'\n *\n * function PostsFetchingIndicator() {\n * // How many queries matching the posts prefix are fetching?\n * const isFetchingPosts = useIsFetching({ queryKey: ['posts'] })\n *\n * return isFetchingPosts ? <span>Refreshing posts...</span> : null\n * }\n * ```\n * @example\n * A global loading indicator for any query fetching in the background, not just the ones on screen:\n * ```tsx\n * import { useIsFetching } from '@tanstack/react-query'\n *\n * function GlobalLoadingIndicator() {\n * const isFetching = useIsFetching()\n *\n * return isFetching ? (\n * <div>Queries are fetching in the background...</div>\n * ) : null\n * }\n * ```\n */\nexport function useIsFetching(\n filters?: QueryFilters,\n queryClient?: QueryClient,\n): number {\n const client = useQueryClient(queryClient)\n const queryCache = client.getQueryCache()\n\n return React.useSyncExternalStore(\n React.useCallback(\n (onStoreChange) =>\n queryCache.subscribe(notifyManager.batchCalls(onStoreChange)),\n [queryCache],\n ),\n () => client.isFetching(filters),\n () => client.isFetching(filters),\n )\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAwCA,SAAgB,cACd,SACA,aACQ;CACR,MAAM,SAASA,4BAAAA,eAAe,WAAW;CACzC,MAAM,aAAa,OAAO,cAAc;CAExC,OAAOC,MAAM,qBACXA,MAAM,aACH,kBACC,WAAW,UAAUC,qBAAAA,cAAc,WAAW,aAAa,CAAC,GAC9D,CAAC,UAAU,CACb,SACM,OAAO,WAAW,OAAO,SACzB,OAAO,WAAW,OAAO,CACjC;AACF"}
|
|
@@ -3,13 +3,11 @@ import { QueryClient, QueryFilters } from "@tanstack/query-core";
|
|
|
3
3
|
/**
|
|
4
4
|
* The `useIsFetching` hook returns the `number` of the queries that your application is loading or fetching in
|
|
5
5
|
* the background (useful for app-wide loading indicators).
|
|
6
|
-
*
|
|
7
6
|
* @param filters - The {@link QueryFilters} to narrow down the matched queries.
|
|
8
7
|
* @param queryClient - Use this to use a custom `QueryClient`. Otherwise, the one from the nearest context will
|
|
9
8
|
* be used.
|
|
10
9
|
* @returns Will be the `number` of the queries that your application is currently loading or fetching in the
|
|
11
10
|
* background.
|
|
12
|
-
*
|
|
13
11
|
* @example
|
|
14
12
|
* ```tsx
|
|
15
13
|
* import { useIsFetching } from '@tanstack/react-query'
|
|
@@ -21,7 +19,6 @@ import { QueryClient, QueryFilters } from "@tanstack/query-core";
|
|
|
21
19
|
* return isFetchingPosts ? <span>Refreshing posts...</span> : null
|
|
22
20
|
* }
|
|
23
21
|
* ```
|
|
24
|
-
*
|
|
25
22
|
* @example
|
|
26
23
|
* A global loading indicator for any query fetching in the background, not just the ones on screen:
|
|
27
24
|
* ```tsx
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useIsFetching.d.cts","names":[],"sources":["../../src/useIsFetching.ts"],"mappings":"
|
|
1
|
+
{"version":3,"file":"useIsFetching.d.cts","names":[],"sources":["../../src/useIsFetching.ts"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;wBAwCgB,cACd,UAAU,cACV,cAAc"}
|
|
@@ -3,13 +3,11 @@ import { QueryClient, QueryFilters } from "@tanstack/query-core";
|
|
|
3
3
|
/**
|
|
4
4
|
* The `useIsFetching` hook returns the `number` of the queries that your application is loading or fetching in
|
|
5
5
|
* the background (useful for app-wide loading indicators).
|
|
6
|
-
*
|
|
7
6
|
* @param filters - The {@link QueryFilters} to narrow down the matched queries.
|
|
8
7
|
* @param queryClient - Use this to use a custom `QueryClient`. Otherwise, the one from the nearest context will
|
|
9
8
|
* be used.
|
|
10
9
|
* @returns Will be the `number` of the queries that your application is currently loading or fetching in the
|
|
11
10
|
* background.
|
|
12
|
-
*
|
|
13
11
|
* @example
|
|
14
12
|
* ```tsx
|
|
15
13
|
* import { useIsFetching } from '@tanstack/react-query'
|
|
@@ -21,7 +19,6 @@ import { QueryClient, QueryFilters } from "@tanstack/query-core";
|
|
|
21
19
|
* return isFetchingPosts ? <span>Refreshing posts...</span> : null
|
|
22
20
|
* }
|
|
23
21
|
* ```
|
|
24
|
-
*
|
|
25
22
|
* @example
|
|
26
23
|
* A global loading indicator for any query fetching in the background, not just the ones on screen:
|
|
27
24
|
* ```tsx
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useIsFetching.d.ts","names":[],"sources":["../../src/useIsFetching.ts"],"mappings":"
|
|
1
|
+
{"version":3,"file":"useIsFetching.d.ts","names":[],"sources":["../../src/useIsFetching.ts"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;wBAwCgB,cACd,UAAU,cACV,cAAc"}
|
|
@@ -6,13 +6,11 @@ import { notifyManager } from "@tanstack/query-core";
|
|
|
6
6
|
/**
|
|
7
7
|
* The `useIsFetching` hook returns the `number` of the queries that your application is loading or fetching in
|
|
8
8
|
* the background (useful for app-wide loading indicators).
|
|
9
|
-
*
|
|
10
9
|
* @param filters - The {@link QueryFilters} to narrow down the matched queries.
|
|
11
10
|
* @param queryClient - Use this to use a custom `QueryClient`. Otherwise, the one from the nearest context will
|
|
12
11
|
* be used.
|
|
13
12
|
* @returns Will be the `number` of the queries that your application is currently loading or fetching in the
|
|
14
13
|
* background.
|
|
15
|
-
*
|
|
16
14
|
* @example
|
|
17
15
|
* ```tsx
|
|
18
16
|
* import { useIsFetching } from '@tanstack/react-query'
|
|
@@ -24,7 +22,6 @@ import { notifyManager } from "@tanstack/query-core";
|
|
|
24
22
|
* return isFetchingPosts ? <span>Refreshing posts...</span> : null
|
|
25
23
|
* }
|
|
26
24
|
* ```
|
|
27
|
-
*
|
|
28
25
|
* @example
|
|
29
26
|
* A global loading indicator for any query fetching in the background, not just the ones on screen:
|
|
30
27
|
* ```tsx
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useIsFetching.js","names":[],"sources":["../../src/useIsFetching.ts"],"sourcesContent":["'use client'\nimport * as React from 'react'\nimport { notifyManager } from '@tanstack/query-core'\n\nimport { useQueryClient } from './QueryClientProvider'\nimport type { QueryClient, QueryFilters } from '@tanstack/query-core'\n\n/**\n * The `useIsFetching` hook returns the `number` of the queries that your application is loading or fetching in\n * the background (useful for app-wide loading indicators).\n
|
|
1
|
+
{"version":3,"file":"useIsFetching.js","names":[],"sources":["../../src/useIsFetching.ts"],"sourcesContent":["'use client'\nimport * as React from 'react'\nimport { notifyManager } from '@tanstack/query-core'\n\nimport { useQueryClient } from './QueryClientProvider'\nimport type { QueryClient, QueryFilters } from '@tanstack/query-core'\n\n/**\n * The `useIsFetching` hook returns the `number` of the queries that your application is loading or fetching in\n * the background (useful for app-wide loading indicators).\n * @param filters - The {@link QueryFilters} to narrow down the matched queries.\n * @param queryClient - Use this to use a custom `QueryClient`. Otherwise, the one from the nearest context will\n * be used.\n * @returns Will be the `number` of the queries that your application is currently loading or fetching in the\n * background.\n * @example\n * ```tsx\n * import { useIsFetching } from '@tanstack/react-query'\n *\n * function PostsFetchingIndicator() {\n * // How many queries matching the posts prefix are fetching?\n * const isFetchingPosts = useIsFetching({ queryKey: ['posts'] })\n *\n * return isFetchingPosts ? <span>Refreshing posts...</span> : null\n * }\n * ```\n * @example\n * A global loading indicator for any query fetching in the background, not just the ones on screen:\n * ```tsx\n * import { useIsFetching } from '@tanstack/react-query'\n *\n * function GlobalLoadingIndicator() {\n * const isFetching = useIsFetching()\n *\n * return isFetching ? (\n * <div>Queries are fetching in the background...</div>\n * ) : null\n * }\n * ```\n */\nexport function useIsFetching(\n filters?: QueryFilters,\n queryClient?: QueryClient,\n): number {\n const client = useQueryClient(queryClient)\n const queryCache = client.getQueryCache()\n\n return React.useSyncExternalStore(\n React.useCallback(\n (onStoreChange) =>\n queryCache.subscribe(notifyManager.batchCalls(onStoreChange)),\n [queryCache],\n ),\n () => client.isFetching(filters),\n () => client.isFetching(filters),\n )\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAwCA,SAAgB,cACd,SACA,aACQ;CACR,MAAM,SAAS,eAAe,WAAW;CACzC,MAAM,aAAa,OAAO,cAAc;CAExC,OAAO,MAAM,qBACX,MAAM,aACH,kBACC,WAAW,UAAU,cAAc,WAAW,aAAa,CAAC,GAC9D,CAAC,UAAU,CACb,SACM,OAAO,WAAW,OAAO,SACzB,OAAO,WAAW,OAAO,CACjC;AACF"}
|