@tanstack/query-core 5.35.4 → 5.36.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/build/legacy/hydration.d.cts +1 -1
- package/build/legacy/hydration.d.ts +1 -1
- package/build/legacy/index.d.cts +1 -1
- package/build/legacy/index.d.ts +1 -1
- package/build/legacy/infiniteQueryBehavior.d.cts +1 -1
- package/build/legacy/infiniteQueryBehavior.d.ts +1 -1
- package/build/legacy/infiniteQueryObserver.cjs +14 -7
- package/build/legacy/infiniteQueryObserver.cjs.map +1 -1
- package/build/legacy/infiniteQueryObserver.d.cts +1 -1
- package/build/legacy/infiniteQueryObserver.d.ts +1 -1
- package/build/legacy/infiniteQueryObserver.js +14 -7
- package/build/legacy/infiniteQueryObserver.js.map +1 -1
- package/build/legacy/mutation.d.cts +1 -1
- package/build/legacy/mutation.d.ts +1 -1
- package/build/legacy/mutationCache.d.cts +1 -1
- package/build/legacy/mutationCache.d.ts +1 -1
- package/build/legacy/mutationObserver.d.cts +1 -1
- package/build/legacy/mutationObserver.d.ts +1 -1
- package/build/legacy/queriesObserver.d.cts +1 -1
- package/build/legacy/queriesObserver.d.ts +1 -1
- package/build/legacy/query.d.cts +1 -1
- package/build/legacy/query.d.ts +1 -1
- package/build/legacy/queryCache.d.cts +1 -1
- package/build/legacy/queryCache.d.ts +1 -1
- package/build/legacy/queryClient.d.cts +1 -1
- package/build/legacy/queryClient.d.ts +1 -1
- package/build/legacy/queryObserver.d.cts +1 -1
- package/build/legacy/queryObserver.d.ts +1 -1
- package/build/legacy/retryer.d.cts +1 -1
- package/build/legacy/retryer.d.ts +1 -1
- package/build/legacy/{types-4So4yn86.d.ts → types-B0i0SaOM.d.ts} +202 -1
- package/build/legacy/{types-t-GGY-tI.d.cts → types-D3f-7LPM.d.cts} +202 -1
- package/build/legacy/types.cjs.map +1 -1
- package/build/legacy/types.d.cts +1 -1
- package/build/legacy/types.d.ts +1 -1
- package/build/legacy/utils.d.cts +1 -1
- package/build/legacy/utils.d.ts +1 -1
- package/build/modern/hydration.d.cts +1 -1
- package/build/modern/hydration.d.ts +1 -1
- package/build/modern/index.d.cts +1 -1
- package/build/modern/index.d.ts +1 -1
- package/build/modern/infiniteQueryBehavior.d.cts +1 -1
- package/build/modern/infiniteQueryBehavior.d.ts +1 -1
- package/build/modern/infiniteQueryObserver.cjs +13 -6
- package/build/modern/infiniteQueryObserver.cjs.map +1 -1
- package/build/modern/infiniteQueryObserver.d.cts +1 -1
- package/build/modern/infiniteQueryObserver.d.ts +1 -1
- package/build/modern/infiniteQueryObserver.js +13 -6
- package/build/modern/infiniteQueryObserver.js.map +1 -1
- package/build/modern/mutation.d.cts +1 -1
- package/build/modern/mutation.d.ts +1 -1
- package/build/modern/mutationCache.d.cts +1 -1
- package/build/modern/mutationCache.d.ts +1 -1
- package/build/modern/mutationObserver.d.cts +1 -1
- package/build/modern/mutationObserver.d.ts +1 -1
- package/build/modern/queriesObserver.d.cts +1 -1
- package/build/modern/queriesObserver.d.ts +1 -1
- package/build/modern/query.d.cts +1 -1
- package/build/modern/query.d.ts +1 -1
- package/build/modern/queryCache.d.cts +1 -1
- package/build/modern/queryCache.d.ts +1 -1
- package/build/modern/queryClient.d.cts +1 -1
- package/build/modern/queryClient.d.ts +1 -1
- package/build/modern/queryObserver.d.cts +1 -1
- package/build/modern/queryObserver.d.ts +1 -1
- package/build/modern/retryer.d.cts +1 -1
- package/build/modern/retryer.d.ts +1 -1
- package/build/modern/{types-4So4yn86.d.ts → types-B0i0SaOM.d.ts} +202 -1
- package/build/modern/{types-t-GGY-tI.d.cts → types-D3f-7LPM.d.cts} +202 -1
- package/build/modern/types.cjs.map +1 -1
- package/build/modern/types.d.cts +1 -1
- package/build/modern/types.d.ts +1 -1
- package/build/modern/utils.d.cts +1 -1
- package/build/modern/utils.d.ts +1 -1
- package/package.json +1 -1
- package/src/__tests__/infiniteQueryObserver.test-d.tsx +2 -0
- package/src/infiniteQueryObserver.ts +16 -8
- package/src/types.ts +202 -1
|
@@ -716,6 +716,13 @@ interface ResultOptions {
|
|
|
716
716
|
throwOnError?: boolean;
|
|
717
717
|
}
|
|
718
718
|
interface RefetchOptions extends ResultOptions {
|
|
719
|
+
/**
|
|
720
|
+
* If set to `true`, a currently running request will be cancelled before a new request is made
|
|
721
|
+
*
|
|
722
|
+
* If set to `false`, no refetch will be made if there is already a request running.
|
|
723
|
+
*
|
|
724
|
+
* Defaults to `true`.
|
|
725
|
+
*/
|
|
719
726
|
cancelRefetch?: boolean;
|
|
720
727
|
}
|
|
721
728
|
interface InvalidateQueryFilters extends QueryFilters {
|
|
@@ -728,41 +735,146 @@ interface InvalidateOptions extends RefetchOptions {
|
|
|
728
735
|
interface ResetOptions extends RefetchOptions {
|
|
729
736
|
}
|
|
730
737
|
interface FetchNextPageOptions extends ResultOptions {
|
|
738
|
+
/**
|
|
739
|
+
* If set to `true`, calling `fetchNextPage` repeatedly will invoke `queryFn` every time,
|
|
740
|
+
* whether the previous invocation has resolved or not. Also, the result from previous invocations will be ignored.
|
|
741
|
+
*
|
|
742
|
+
* If set to `false`, calling `fetchNextPage` repeatedly won't have any effect until the first invocation has resolved.
|
|
743
|
+
*
|
|
744
|
+
* Defaults to `true`.
|
|
745
|
+
*/
|
|
731
746
|
cancelRefetch?: boolean;
|
|
732
747
|
}
|
|
733
748
|
interface FetchPreviousPageOptions extends ResultOptions {
|
|
749
|
+
/**
|
|
750
|
+
* If set to `true`, calling `fetchPreviousPage` repeatedly will invoke `queryFn` every time,
|
|
751
|
+
* whether the previous invocation has resolved or not. Also, the result from previous invocations will be ignored.
|
|
752
|
+
*
|
|
753
|
+
* If set to `false`, calling `fetchPreviousPage` repeatedly won't have any effect until the first invocation has resolved.
|
|
754
|
+
*
|
|
755
|
+
* Defaults to `true`.
|
|
756
|
+
*/
|
|
734
757
|
cancelRefetch?: boolean;
|
|
735
758
|
}
|
|
736
759
|
type QueryStatus = 'pending' | 'error' | 'success';
|
|
737
760
|
type FetchStatus = 'fetching' | 'paused' | 'idle';
|
|
738
761
|
interface QueryObserverBaseResult<TData = unknown, TError = DefaultError> {
|
|
762
|
+
/**
|
|
763
|
+
* The last successfully resolved data for the query.
|
|
764
|
+
* - Defaults to `undefined`.
|
|
765
|
+
*/
|
|
739
766
|
data: TData | undefined;
|
|
767
|
+
/**
|
|
768
|
+
* The timestamp for when the query most recently returned the `status` as `"success"`.
|
|
769
|
+
*/
|
|
740
770
|
dataUpdatedAt: number;
|
|
771
|
+
/**
|
|
772
|
+
* The error object for the query, if an error was thrown.
|
|
773
|
+
* - Defaults to `null`.
|
|
774
|
+
*/
|
|
741
775
|
error: TError | null;
|
|
776
|
+
/**
|
|
777
|
+
* The timestamp for when the query most recently returned the `status` as `"error"`.
|
|
778
|
+
*/
|
|
742
779
|
errorUpdatedAt: number;
|
|
780
|
+
/**
|
|
781
|
+
* The failure count for the query.
|
|
782
|
+
* - Incremented every time the query fails.
|
|
783
|
+
* - Reset to `0` when the query succeeds.
|
|
784
|
+
*/
|
|
743
785
|
failureCount: number;
|
|
786
|
+
/**
|
|
787
|
+
* The failure reason for the query retry.
|
|
788
|
+
* - Reset to `null` when the query succeeds.
|
|
789
|
+
*/
|
|
744
790
|
failureReason: TError | null;
|
|
791
|
+
/**
|
|
792
|
+
* The sum of all errors.
|
|
793
|
+
*/
|
|
745
794
|
errorUpdateCount: number;
|
|
795
|
+
/**
|
|
796
|
+
* A derived boolean from the `status` variable, provided for convenience.
|
|
797
|
+
* - `true` if the query attempt resulted in an error.
|
|
798
|
+
*/
|
|
746
799
|
isError: boolean;
|
|
800
|
+
/**
|
|
801
|
+
* Will be `true` if the query has been fetched.
|
|
802
|
+
*/
|
|
747
803
|
isFetched: boolean;
|
|
804
|
+
/**
|
|
805
|
+
* Will be `true` if the query has been fetched after the component mounted.
|
|
806
|
+
* - This property can be used to not show any previously cached data.
|
|
807
|
+
*/
|
|
748
808
|
isFetchedAfterMount: boolean;
|
|
809
|
+
/**
|
|
810
|
+
* A derived boolean from the `fetchStatus` variable, provided for convenience.
|
|
811
|
+
* - `true` whenever the `queryFn` is executing, which includes initial `pending` as well as background refetch.
|
|
812
|
+
*/
|
|
749
813
|
isFetching: boolean;
|
|
814
|
+
/**
|
|
815
|
+
* Is `true` whenever the first fetch for a query is in-flight.
|
|
816
|
+
* - Is the same as `isFetching && isPending`.
|
|
817
|
+
*/
|
|
750
818
|
isLoading: boolean;
|
|
819
|
+
/**
|
|
820
|
+
* Will be `pending` if there's no cached data and no query attempt was finished yet.
|
|
821
|
+
*/
|
|
751
822
|
isPending: boolean;
|
|
823
|
+
/**
|
|
824
|
+
* Will be `true` if the query failed while fetching for the first time.
|
|
825
|
+
*/
|
|
752
826
|
isLoadingError: boolean;
|
|
753
827
|
/**
|
|
754
|
-
* @deprecated isInitialLoading is being deprecated in favor of isLoading
|
|
828
|
+
* @deprecated `isInitialLoading` is being deprecated in favor of `isLoading`
|
|
755
829
|
* and will be removed in the next major version.
|
|
756
830
|
*/
|
|
757
831
|
isInitialLoading: boolean;
|
|
832
|
+
/**
|
|
833
|
+
* A derived boolean from the `fetchStatus` variable, provided for convenience.
|
|
834
|
+
* - The query wanted to fetch, but has been `paused`.
|
|
835
|
+
*/
|
|
758
836
|
isPaused: boolean;
|
|
837
|
+
/**
|
|
838
|
+
* Will be `true` if the data shown is the placeholder data.
|
|
839
|
+
*/
|
|
759
840
|
isPlaceholderData: boolean;
|
|
841
|
+
/**
|
|
842
|
+
* Will be `true` if the query failed while refetching.
|
|
843
|
+
*/
|
|
760
844
|
isRefetchError: boolean;
|
|
845
|
+
/**
|
|
846
|
+
* Is `true` whenever a background refetch is in-flight, which _does not_ include initial `pending`.
|
|
847
|
+
* - Is the same as `isFetching && !isPending`.
|
|
848
|
+
*/
|
|
761
849
|
isRefetching: boolean;
|
|
850
|
+
/**
|
|
851
|
+
* Will be `true` if the data in the cache is invalidated or if the data is older than the given `staleTime`.
|
|
852
|
+
*/
|
|
762
853
|
isStale: boolean;
|
|
854
|
+
/**
|
|
855
|
+
* A derived boolean from the `status` variable, provided for convenience.
|
|
856
|
+
* - `true` if the query has received a response with no errors and is ready to display its data.
|
|
857
|
+
*/
|
|
763
858
|
isSuccess: boolean;
|
|
859
|
+
/**
|
|
860
|
+
* A function to manually refetch the query.
|
|
861
|
+
*/
|
|
764
862
|
refetch: (options?: RefetchOptions) => Promise<QueryObserverResult<TData, TError>>;
|
|
863
|
+
/**
|
|
864
|
+
* The status of the query.
|
|
865
|
+
* - Will be:
|
|
866
|
+
* - `pending` if there's no cached data and no query attempt was finished yet.
|
|
867
|
+
* - `error` if the query attempt resulted in an error.
|
|
868
|
+
* - `success` if the query has received a response with no errors and is ready to display its data.
|
|
869
|
+
*/
|
|
765
870
|
status: QueryStatus;
|
|
871
|
+
/**
|
|
872
|
+
* The fetch status of the query.
|
|
873
|
+
* - `fetching`: Is `true` whenever the queryFn is executing, which includes initial `pending` as well as background refetch.
|
|
874
|
+
* - `paused`: The query wanted to fetch, but has been `paused`.
|
|
875
|
+
* - `idle`: The query is not fetching.
|
|
876
|
+
* - See [Network Mode](https://tanstack.com/query/latest/docs/framework/react/guides/network-mode) for more information.
|
|
877
|
+
*/
|
|
766
878
|
fetchStatus: FetchStatus;
|
|
767
879
|
}
|
|
768
880
|
interface QueryObserverPendingResult<TData = unknown, TError = DefaultError> extends QueryObserverBaseResult<TData, TError> {
|
|
@@ -822,11 +934,37 @@ interface QueryObserverSuccessResult<TData = unknown, TError = DefaultError> ext
|
|
|
822
934
|
type DefinedQueryObserverResult<TData = unknown, TError = DefaultError> = QueryObserverRefetchErrorResult<TData, TError> | QueryObserverSuccessResult<TData, TError>;
|
|
823
935
|
type QueryObserverResult<TData = unknown, TError = DefaultError> = DefinedQueryObserverResult<TData, TError> | QueryObserverLoadingErrorResult<TData, TError> | QueryObserverLoadingResult<TData, TError> | QueryObserverPendingResult<TData, TError>;
|
|
824
936
|
interface InfiniteQueryObserverBaseResult<TData = unknown, TError = DefaultError> extends QueryObserverBaseResult<TData, TError> {
|
|
937
|
+
/**
|
|
938
|
+
* This function allows you to fetch the next "page" of results.
|
|
939
|
+
*/
|
|
825
940
|
fetchNextPage: (options?: FetchNextPageOptions) => Promise<InfiniteQueryObserverResult<TData, TError>>;
|
|
941
|
+
/**
|
|
942
|
+
* This function allows you to fetch the previous "page" of results.
|
|
943
|
+
*/
|
|
826
944
|
fetchPreviousPage: (options?: FetchPreviousPageOptions) => Promise<InfiniteQueryObserverResult<TData, TError>>;
|
|
945
|
+
/**
|
|
946
|
+
* Will be `true` if there is a next page to be fetched (known via the `getNextPageParam` option).
|
|
947
|
+
*/
|
|
827
948
|
hasNextPage: boolean;
|
|
949
|
+
/**
|
|
950
|
+
* Will be `true` if there is a previous page to be fetched (known via the `getPreviousPageParam` option).
|
|
951
|
+
*/
|
|
828
952
|
hasPreviousPage: boolean;
|
|
953
|
+
/**
|
|
954
|
+
* Will be `true` if the query failed while fetching the next page.
|
|
955
|
+
*/
|
|
956
|
+
isFetchNextPageError: boolean;
|
|
957
|
+
/**
|
|
958
|
+
* Will be `true` while fetching the next page with `fetchNextPage`.
|
|
959
|
+
*/
|
|
829
960
|
isFetchingNextPage: boolean;
|
|
961
|
+
/**
|
|
962
|
+
* Will be `true` if the query failed while fetching the previous page.
|
|
963
|
+
*/
|
|
964
|
+
isFetchPreviousPageError: boolean;
|
|
965
|
+
/**
|
|
966
|
+
* Will be `true` while fetching the previous page with `fetchPreviousPage`.
|
|
967
|
+
*/
|
|
830
968
|
isFetchingPreviousPage: boolean;
|
|
831
969
|
}
|
|
832
970
|
interface InfiniteQueryObserverPendingResult<TData = unknown, TError = DefaultError> extends InfiniteQueryObserverBaseResult<TData, TError> {
|
|
@@ -836,6 +974,8 @@ interface InfiniteQueryObserverPendingResult<TData = unknown, TError = DefaultEr
|
|
|
836
974
|
isPending: true;
|
|
837
975
|
isLoadingError: false;
|
|
838
976
|
isRefetchError: false;
|
|
977
|
+
isFetchNextPageError: false;
|
|
978
|
+
isFetchPreviousPageError: false;
|
|
839
979
|
isSuccess: false;
|
|
840
980
|
status: 'pending';
|
|
841
981
|
}
|
|
@@ -847,6 +987,8 @@ interface InfiniteQueryObserverLoadingResult<TData = unknown, TError = DefaultEr
|
|
|
847
987
|
isLoading: true;
|
|
848
988
|
isLoadingError: false;
|
|
849
989
|
isRefetchError: false;
|
|
990
|
+
isFetchNextPageError: false;
|
|
991
|
+
isFetchPreviousPageError: false;
|
|
850
992
|
isSuccess: false;
|
|
851
993
|
status: 'pending';
|
|
852
994
|
}
|
|
@@ -858,6 +1000,8 @@ interface InfiniteQueryObserverLoadingErrorResult<TData = unknown, TError = Defa
|
|
|
858
1000
|
isLoading: false;
|
|
859
1001
|
isLoadingError: true;
|
|
860
1002
|
isRefetchError: false;
|
|
1003
|
+
isFetchNextPageError: false;
|
|
1004
|
+
isFetchPreviousPageError: false;
|
|
861
1005
|
isSuccess: false;
|
|
862
1006
|
status: 'error';
|
|
863
1007
|
}
|
|
@@ -869,6 +1013,8 @@ interface InfiniteQueryObserverRefetchErrorResult<TData = unknown, TError = Defa
|
|
|
869
1013
|
isLoading: false;
|
|
870
1014
|
isLoadingError: false;
|
|
871
1015
|
isRefetchError: true;
|
|
1016
|
+
isFetchNextPageError: false;
|
|
1017
|
+
isFetchPreviousPageError: false;
|
|
872
1018
|
isSuccess: false;
|
|
873
1019
|
status: 'error';
|
|
874
1020
|
}
|
|
@@ -880,6 +1026,8 @@ interface InfiniteQueryObserverSuccessResult<TData = unknown, TError = DefaultEr
|
|
|
880
1026
|
isLoading: false;
|
|
881
1027
|
isLoadingError: false;
|
|
882
1028
|
isRefetchError: false;
|
|
1029
|
+
isFetchNextPageError: false;
|
|
1030
|
+
isFetchPreviousPageError: false;
|
|
883
1031
|
isSuccess: true;
|
|
884
1032
|
status: 'success';
|
|
885
1033
|
}
|
|
@@ -919,11 +1067,64 @@ interface MutateOptions<TData = unknown, TError = DefaultError, TVariables = voi
|
|
|
919
1067
|
}
|
|
920
1068
|
type MutateFunction<TData = unknown, TError = DefaultError, TVariables = void, TContext = unknown> = (variables: TVariables, options?: MutateOptions<TData, TError, TVariables, TContext>) => Promise<TData>;
|
|
921
1069
|
interface MutationObserverBaseResult<TData = unknown, TError = DefaultError, TVariables = void, TContext = unknown> extends MutationState<TData, TError, TVariables, TContext> {
|
|
1070
|
+
/**
|
|
1071
|
+
* The last successfully resolved data for the mutation.
|
|
1072
|
+
* - Defaults to `undefined`.
|
|
1073
|
+
*/
|
|
1074
|
+
data: TData | undefined;
|
|
1075
|
+
/**
|
|
1076
|
+
* The variables object passed to the `mutationFn`.
|
|
1077
|
+
* - Defaults to `undefined`.
|
|
1078
|
+
*/
|
|
1079
|
+
variables: TVariables | undefined;
|
|
1080
|
+
/**
|
|
1081
|
+
* The error object for the mutation, if an error was encountered.
|
|
1082
|
+
* - Defaults to `null`.
|
|
1083
|
+
*/
|
|
1084
|
+
error: TError | null;
|
|
1085
|
+
/**
|
|
1086
|
+
* A boolean variable derived from `status`.
|
|
1087
|
+
* - `true` if the last mutation attempt resulted in an error.
|
|
1088
|
+
*/
|
|
922
1089
|
isError: boolean;
|
|
1090
|
+
/**
|
|
1091
|
+
* A boolean variable derived from `status`.
|
|
1092
|
+
* - `true` if the mutation is in its initial state prior to executing.
|
|
1093
|
+
*/
|
|
923
1094
|
isIdle: boolean;
|
|
1095
|
+
/**
|
|
1096
|
+
* A boolean variable derived from `status`.
|
|
1097
|
+
* - `true` if the mutation is currently executing.
|
|
1098
|
+
*/
|
|
924
1099
|
isPending: boolean;
|
|
1100
|
+
/**
|
|
1101
|
+
* A boolean variable derived from `status`.
|
|
1102
|
+
* - `true` if the last mutation attempt was successful.
|
|
1103
|
+
*/
|
|
925
1104
|
isSuccess: boolean;
|
|
1105
|
+
/**
|
|
1106
|
+
* The status of the mutation.
|
|
1107
|
+
* - Will be:
|
|
1108
|
+
* - `idle` initial status prior to the mutation function executing.
|
|
1109
|
+
* - `pending` if the mutation is currently executing.
|
|
1110
|
+
* - `error` if the last mutation attempt resulted in an error.
|
|
1111
|
+
* - `success` if the last mutation attempt was successful.
|
|
1112
|
+
*/
|
|
1113
|
+
status: MutationStatus;
|
|
1114
|
+
/**
|
|
1115
|
+
* The mutation function you can call with variables to trigger the mutation and optionally hooks on additional callback options.
|
|
1116
|
+
* @param variables - The variables object to pass to the `mutationFn`.
|
|
1117
|
+
* @param options.onSuccess - This function will fire when the mutation is successful and will be passed the mutation's result.
|
|
1118
|
+
* @param options.onError - This function will fire if the mutation encounters an error and will be passed the error.
|
|
1119
|
+
* @param options.onSettled - This function will fire when the mutation is either successfully fetched or encounters an error and be passed either the data or error.
|
|
1120
|
+
* @remarks
|
|
1121
|
+
* - If you make multiple requests, `onSuccess` will fire only after the latest call you've made.
|
|
1122
|
+
* - All the callback functions (`onSuccess`, `onError`, `onSettled`) are void functions, and the returned value will be ignored.
|
|
1123
|
+
*/
|
|
926
1124
|
mutate: MutateFunction<TData, TError, TVariables, TContext>;
|
|
1125
|
+
/**
|
|
1126
|
+
* A function to clean the mutation internal state (i.e., it resets the mutation to its initial state).
|
|
1127
|
+
*/
|
|
927
1128
|
reset: () => void;
|
|
928
1129
|
}
|
|
929
1130
|
interface MutationObserverIdleResult<TData = unknown, TError = DefaultError, TVariables = void, TContext = unknown> extends MutationObserverBaseResult<TData, TError, TVariables, TContext> {
|
|
@@ -716,6 +716,13 @@ interface ResultOptions {
|
|
|
716
716
|
throwOnError?: boolean;
|
|
717
717
|
}
|
|
718
718
|
interface RefetchOptions extends ResultOptions {
|
|
719
|
+
/**
|
|
720
|
+
* If set to `true`, a currently running request will be cancelled before a new request is made
|
|
721
|
+
*
|
|
722
|
+
* If set to `false`, no refetch will be made if there is already a request running.
|
|
723
|
+
*
|
|
724
|
+
* Defaults to `true`.
|
|
725
|
+
*/
|
|
719
726
|
cancelRefetch?: boolean;
|
|
720
727
|
}
|
|
721
728
|
interface InvalidateQueryFilters extends QueryFilters {
|
|
@@ -728,41 +735,146 @@ interface InvalidateOptions extends RefetchOptions {
|
|
|
728
735
|
interface ResetOptions extends RefetchOptions {
|
|
729
736
|
}
|
|
730
737
|
interface FetchNextPageOptions extends ResultOptions {
|
|
738
|
+
/**
|
|
739
|
+
* If set to `true`, calling `fetchNextPage` repeatedly will invoke `queryFn` every time,
|
|
740
|
+
* whether the previous invocation has resolved or not. Also, the result from previous invocations will be ignored.
|
|
741
|
+
*
|
|
742
|
+
* If set to `false`, calling `fetchNextPage` repeatedly won't have any effect until the first invocation has resolved.
|
|
743
|
+
*
|
|
744
|
+
* Defaults to `true`.
|
|
745
|
+
*/
|
|
731
746
|
cancelRefetch?: boolean;
|
|
732
747
|
}
|
|
733
748
|
interface FetchPreviousPageOptions extends ResultOptions {
|
|
749
|
+
/**
|
|
750
|
+
* If set to `true`, calling `fetchPreviousPage` repeatedly will invoke `queryFn` every time,
|
|
751
|
+
* whether the previous invocation has resolved or not. Also, the result from previous invocations will be ignored.
|
|
752
|
+
*
|
|
753
|
+
* If set to `false`, calling `fetchPreviousPage` repeatedly won't have any effect until the first invocation has resolved.
|
|
754
|
+
*
|
|
755
|
+
* Defaults to `true`.
|
|
756
|
+
*/
|
|
734
757
|
cancelRefetch?: boolean;
|
|
735
758
|
}
|
|
736
759
|
type QueryStatus = 'pending' | 'error' | 'success';
|
|
737
760
|
type FetchStatus = 'fetching' | 'paused' | 'idle';
|
|
738
761
|
interface QueryObserverBaseResult<TData = unknown, TError = DefaultError> {
|
|
762
|
+
/**
|
|
763
|
+
* The last successfully resolved data for the query.
|
|
764
|
+
* - Defaults to `undefined`.
|
|
765
|
+
*/
|
|
739
766
|
data: TData | undefined;
|
|
767
|
+
/**
|
|
768
|
+
* The timestamp for when the query most recently returned the `status` as `"success"`.
|
|
769
|
+
*/
|
|
740
770
|
dataUpdatedAt: number;
|
|
771
|
+
/**
|
|
772
|
+
* The error object for the query, if an error was thrown.
|
|
773
|
+
* - Defaults to `null`.
|
|
774
|
+
*/
|
|
741
775
|
error: TError | null;
|
|
776
|
+
/**
|
|
777
|
+
* The timestamp for when the query most recently returned the `status` as `"error"`.
|
|
778
|
+
*/
|
|
742
779
|
errorUpdatedAt: number;
|
|
780
|
+
/**
|
|
781
|
+
* The failure count for the query.
|
|
782
|
+
* - Incremented every time the query fails.
|
|
783
|
+
* - Reset to `0` when the query succeeds.
|
|
784
|
+
*/
|
|
743
785
|
failureCount: number;
|
|
786
|
+
/**
|
|
787
|
+
* The failure reason for the query retry.
|
|
788
|
+
* - Reset to `null` when the query succeeds.
|
|
789
|
+
*/
|
|
744
790
|
failureReason: TError | null;
|
|
791
|
+
/**
|
|
792
|
+
* The sum of all errors.
|
|
793
|
+
*/
|
|
745
794
|
errorUpdateCount: number;
|
|
795
|
+
/**
|
|
796
|
+
* A derived boolean from the `status` variable, provided for convenience.
|
|
797
|
+
* - `true` if the query attempt resulted in an error.
|
|
798
|
+
*/
|
|
746
799
|
isError: boolean;
|
|
800
|
+
/**
|
|
801
|
+
* Will be `true` if the query has been fetched.
|
|
802
|
+
*/
|
|
747
803
|
isFetched: boolean;
|
|
804
|
+
/**
|
|
805
|
+
* Will be `true` if the query has been fetched after the component mounted.
|
|
806
|
+
* - This property can be used to not show any previously cached data.
|
|
807
|
+
*/
|
|
748
808
|
isFetchedAfterMount: boolean;
|
|
809
|
+
/**
|
|
810
|
+
* A derived boolean from the `fetchStatus` variable, provided for convenience.
|
|
811
|
+
* - `true` whenever the `queryFn` is executing, which includes initial `pending` as well as background refetch.
|
|
812
|
+
*/
|
|
749
813
|
isFetching: boolean;
|
|
814
|
+
/**
|
|
815
|
+
* Is `true` whenever the first fetch for a query is in-flight.
|
|
816
|
+
* - Is the same as `isFetching && isPending`.
|
|
817
|
+
*/
|
|
750
818
|
isLoading: boolean;
|
|
819
|
+
/**
|
|
820
|
+
* Will be `pending` if there's no cached data and no query attempt was finished yet.
|
|
821
|
+
*/
|
|
751
822
|
isPending: boolean;
|
|
823
|
+
/**
|
|
824
|
+
* Will be `true` if the query failed while fetching for the first time.
|
|
825
|
+
*/
|
|
752
826
|
isLoadingError: boolean;
|
|
753
827
|
/**
|
|
754
|
-
* @deprecated isInitialLoading is being deprecated in favor of isLoading
|
|
828
|
+
* @deprecated `isInitialLoading` is being deprecated in favor of `isLoading`
|
|
755
829
|
* and will be removed in the next major version.
|
|
756
830
|
*/
|
|
757
831
|
isInitialLoading: boolean;
|
|
832
|
+
/**
|
|
833
|
+
* A derived boolean from the `fetchStatus` variable, provided for convenience.
|
|
834
|
+
* - The query wanted to fetch, but has been `paused`.
|
|
835
|
+
*/
|
|
758
836
|
isPaused: boolean;
|
|
837
|
+
/**
|
|
838
|
+
* Will be `true` if the data shown is the placeholder data.
|
|
839
|
+
*/
|
|
759
840
|
isPlaceholderData: boolean;
|
|
841
|
+
/**
|
|
842
|
+
* Will be `true` if the query failed while refetching.
|
|
843
|
+
*/
|
|
760
844
|
isRefetchError: boolean;
|
|
845
|
+
/**
|
|
846
|
+
* Is `true` whenever a background refetch is in-flight, which _does not_ include initial `pending`.
|
|
847
|
+
* - Is the same as `isFetching && !isPending`.
|
|
848
|
+
*/
|
|
761
849
|
isRefetching: boolean;
|
|
850
|
+
/**
|
|
851
|
+
* Will be `true` if the data in the cache is invalidated or if the data is older than the given `staleTime`.
|
|
852
|
+
*/
|
|
762
853
|
isStale: boolean;
|
|
854
|
+
/**
|
|
855
|
+
* A derived boolean from the `status` variable, provided for convenience.
|
|
856
|
+
* - `true` if the query has received a response with no errors and is ready to display its data.
|
|
857
|
+
*/
|
|
763
858
|
isSuccess: boolean;
|
|
859
|
+
/**
|
|
860
|
+
* A function to manually refetch the query.
|
|
861
|
+
*/
|
|
764
862
|
refetch: (options?: RefetchOptions) => Promise<QueryObserverResult<TData, TError>>;
|
|
863
|
+
/**
|
|
864
|
+
* The status of the query.
|
|
865
|
+
* - Will be:
|
|
866
|
+
* - `pending` if there's no cached data and no query attempt was finished yet.
|
|
867
|
+
* - `error` if the query attempt resulted in an error.
|
|
868
|
+
* - `success` if the query has received a response with no errors and is ready to display its data.
|
|
869
|
+
*/
|
|
765
870
|
status: QueryStatus;
|
|
871
|
+
/**
|
|
872
|
+
* The fetch status of the query.
|
|
873
|
+
* - `fetching`: Is `true` whenever the queryFn is executing, which includes initial `pending` as well as background refetch.
|
|
874
|
+
* - `paused`: The query wanted to fetch, but has been `paused`.
|
|
875
|
+
* - `idle`: The query is not fetching.
|
|
876
|
+
* - See [Network Mode](https://tanstack.com/query/latest/docs/framework/react/guides/network-mode) for more information.
|
|
877
|
+
*/
|
|
766
878
|
fetchStatus: FetchStatus;
|
|
767
879
|
}
|
|
768
880
|
interface QueryObserverPendingResult<TData = unknown, TError = DefaultError> extends QueryObserverBaseResult<TData, TError> {
|
|
@@ -822,11 +934,37 @@ interface QueryObserverSuccessResult<TData = unknown, TError = DefaultError> ext
|
|
|
822
934
|
type DefinedQueryObserverResult<TData = unknown, TError = DefaultError> = QueryObserverRefetchErrorResult<TData, TError> | QueryObserverSuccessResult<TData, TError>;
|
|
823
935
|
type QueryObserverResult<TData = unknown, TError = DefaultError> = DefinedQueryObserverResult<TData, TError> | QueryObserverLoadingErrorResult<TData, TError> | QueryObserverLoadingResult<TData, TError> | QueryObserverPendingResult<TData, TError>;
|
|
824
936
|
interface InfiniteQueryObserverBaseResult<TData = unknown, TError = DefaultError> extends QueryObserverBaseResult<TData, TError> {
|
|
937
|
+
/**
|
|
938
|
+
* This function allows you to fetch the next "page" of results.
|
|
939
|
+
*/
|
|
825
940
|
fetchNextPage: (options?: FetchNextPageOptions) => Promise<InfiniteQueryObserverResult<TData, TError>>;
|
|
941
|
+
/**
|
|
942
|
+
* This function allows you to fetch the previous "page" of results.
|
|
943
|
+
*/
|
|
826
944
|
fetchPreviousPage: (options?: FetchPreviousPageOptions) => Promise<InfiniteQueryObserverResult<TData, TError>>;
|
|
945
|
+
/**
|
|
946
|
+
* Will be `true` if there is a next page to be fetched (known via the `getNextPageParam` option).
|
|
947
|
+
*/
|
|
827
948
|
hasNextPage: boolean;
|
|
949
|
+
/**
|
|
950
|
+
* Will be `true` if there is a previous page to be fetched (known via the `getPreviousPageParam` option).
|
|
951
|
+
*/
|
|
828
952
|
hasPreviousPage: boolean;
|
|
953
|
+
/**
|
|
954
|
+
* Will be `true` if the query failed while fetching the next page.
|
|
955
|
+
*/
|
|
956
|
+
isFetchNextPageError: boolean;
|
|
957
|
+
/**
|
|
958
|
+
* Will be `true` while fetching the next page with `fetchNextPage`.
|
|
959
|
+
*/
|
|
829
960
|
isFetchingNextPage: boolean;
|
|
961
|
+
/**
|
|
962
|
+
* Will be `true` if the query failed while fetching the previous page.
|
|
963
|
+
*/
|
|
964
|
+
isFetchPreviousPageError: boolean;
|
|
965
|
+
/**
|
|
966
|
+
* Will be `true` while fetching the previous page with `fetchPreviousPage`.
|
|
967
|
+
*/
|
|
830
968
|
isFetchingPreviousPage: boolean;
|
|
831
969
|
}
|
|
832
970
|
interface InfiniteQueryObserverPendingResult<TData = unknown, TError = DefaultError> extends InfiniteQueryObserverBaseResult<TData, TError> {
|
|
@@ -836,6 +974,8 @@ interface InfiniteQueryObserverPendingResult<TData = unknown, TError = DefaultEr
|
|
|
836
974
|
isPending: true;
|
|
837
975
|
isLoadingError: false;
|
|
838
976
|
isRefetchError: false;
|
|
977
|
+
isFetchNextPageError: false;
|
|
978
|
+
isFetchPreviousPageError: false;
|
|
839
979
|
isSuccess: false;
|
|
840
980
|
status: 'pending';
|
|
841
981
|
}
|
|
@@ -847,6 +987,8 @@ interface InfiniteQueryObserverLoadingResult<TData = unknown, TError = DefaultEr
|
|
|
847
987
|
isLoading: true;
|
|
848
988
|
isLoadingError: false;
|
|
849
989
|
isRefetchError: false;
|
|
990
|
+
isFetchNextPageError: false;
|
|
991
|
+
isFetchPreviousPageError: false;
|
|
850
992
|
isSuccess: false;
|
|
851
993
|
status: 'pending';
|
|
852
994
|
}
|
|
@@ -858,6 +1000,8 @@ interface InfiniteQueryObserverLoadingErrorResult<TData = unknown, TError = Defa
|
|
|
858
1000
|
isLoading: false;
|
|
859
1001
|
isLoadingError: true;
|
|
860
1002
|
isRefetchError: false;
|
|
1003
|
+
isFetchNextPageError: false;
|
|
1004
|
+
isFetchPreviousPageError: false;
|
|
861
1005
|
isSuccess: false;
|
|
862
1006
|
status: 'error';
|
|
863
1007
|
}
|
|
@@ -869,6 +1013,8 @@ interface InfiniteQueryObserverRefetchErrorResult<TData = unknown, TError = Defa
|
|
|
869
1013
|
isLoading: false;
|
|
870
1014
|
isLoadingError: false;
|
|
871
1015
|
isRefetchError: true;
|
|
1016
|
+
isFetchNextPageError: false;
|
|
1017
|
+
isFetchPreviousPageError: false;
|
|
872
1018
|
isSuccess: false;
|
|
873
1019
|
status: 'error';
|
|
874
1020
|
}
|
|
@@ -880,6 +1026,8 @@ interface InfiniteQueryObserverSuccessResult<TData = unknown, TError = DefaultEr
|
|
|
880
1026
|
isLoading: false;
|
|
881
1027
|
isLoadingError: false;
|
|
882
1028
|
isRefetchError: false;
|
|
1029
|
+
isFetchNextPageError: false;
|
|
1030
|
+
isFetchPreviousPageError: false;
|
|
883
1031
|
isSuccess: true;
|
|
884
1032
|
status: 'success';
|
|
885
1033
|
}
|
|
@@ -919,11 +1067,64 @@ interface MutateOptions<TData = unknown, TError = DefaultError, TVariables = voi
|
|
|
919
1067
|
}
|
|
920
1068
|
type MutateFunction<TData = unknown, TError = DefaultError, TVariables = void, TContext = unknown> = (variables: TVariables, options?: MutateOptions<TData, TError, TVariables, TContext>) => Promise<TData>;
|
|
921
1069
|
interface MutationObserverBaseResult<TData = unknown, TError = DefaultError, TVariables = void, TContext = unknown> extends MutationState<TData, TError, TVariables, TContext> {
|
|
1070
|
+
/**
|
|
1071
|
+
* The last successfully resolved data for the mutation.
|
|
1072
|
+
* - Defaults to `undefined`.
|
|
1073
|
+
*/
|
|
1074
|
+
data: TData | undefined;
|
|
1075
|
+
/**
|
|
1076
|
+
* The variables object passed to the `mutationFn`.
|
|
1077
|
+
* - Defaults to `undefined`.
|
|
1078
|
+
*/
|
|
1079
|
+
variables: TVariables | undefined;
|
|
1080
|
+
/**
|
|
1081
|
+
* The error object for the mutation, if an error was encountered.
|
|
1082
|
+
* - Defaults to `null`.
|
|
1083
|
+
*/
|
|
1084
|
+
error: TError | null;
|
|
1085
|
+
/**
|
|
1086
|
+
* A boolean variable derived from `status`.
|
|
1087
|
+
* - `true` if the last mutation attempt resulted in an error.
|
|
1088
|
+
*/
|
|
922
1089
|
isError: boolean;
|
|
1090
|
+
/**
|
|
1091
|
+
* A boolean variable derived from `status`.
|
|
1092
|
+
* - `true` if the mutation is in its initial state prior to executing.
|
|
1093
|
+
*/
|
|
923
1094
|
isIdle: boolean;
|
|
1095
|
+
/**
|
|
1096
|
+
* A boolean variable derived from `status`.
|
|
1097
|
+
* - `true` if the mutation is currently executing.
|
|
1098
|
+
*/
|
|
924
1099
|
isPending: boolean;
|
|
1100
|
+
/**
|
|
1101
|
+
* A boolean variable derived from `status`.
|
|
1102
|
+
* - `true` if the last mutation attempt was successful.
|
|
1103
|
+
*/
|
|
925
1104
|
isSuccess: boolean;
|
|
1105
|
+
/**
|
|
1106
|
+
* The status of the mutation.
|
|
1107
|
+
* - Will be:
|
|
1108
|
+
* - `idle` initial status prior to the mutation function executing.
|
|
1109
|
+
* - `pending` if the mutation is currently executing.
|
|
1110
|
+
* - `error` if the last mutation attempt resulted in an error.
|
|
1111
|
+
* - `success` if the last mutation attempt was successful.
|
|
1112
|
+
*/
|
|
1113
|
+
status: MutationStatus;
|
|
1114
|
+
/**
|
|
1115
|
+
* The mutation function you can call with variables to trigger the mutation and optionally hooks on additional callback options.
|
|
1116
|
+
* @param variables - The variables object to pass to the `mutationFn`.
|
|
1117
|
+
* @param options.onSuccess - This function will fire when the mutation is successful and will be passed the mutation's result.
|
|
1118
|
+
* @param options.onError - This function will fire if the mutation encounters an error and will be passed the error.
|
|
1119
|
+
* @param options.onSettled - This function will fire when the mutation is either successfully fetched or encounters an error and be passed either the data or error.
|
|
1120
|
+
* @remarks
|
|
1121
|
+
* - If you make multiple requests, `onSuccess` will fire only after the latest call you've made.
|
|
1122
|
+
* - All the callback functions (`onSuccess`, `onError`, `onSettled`) are void functions, and the returned value will be ignored.
|
|
1123
|
+
*/
|
|
926
1124
|
mutate: MutateFunction<TData, TError, TVariables, TContext>;
|
|
1125
|
+
/**
|
|
1126
|
+
* A function to clean the mutation internal state (i.e., it resets the mutation to its initial state).
|
|
1127
|
+
*/
|
|
927
1128
|
reset: () => void;
|
|
928
1129
|
}
|
|
929
1130
|
interface MutationObserverIdleResult<TData = unknown, TError = DefaultError, TVariables = void, TContext = unknown> extends MutationObserverBaseResult<TData, TError, TVariables, TContext> {
|