@@ -541,9 +541,6 @@ export type MutationTrigger<D extends MutationDefinition<any, any, any, any>> =
541
541
( arg : QueryArgFrom < D > ) : MutationActionCreatorResult < D >
542
542
}
543
543
544
- const defaultQueryStateSelector : QueryStateSelector < any , any > = ( x ) => x
545
- const defaultMutationStateSelector : MutationStateSelector < any , any > = ( x ) => x
546
-
547
544
/**
548
545
* Wrapper around `defaultQueryStateSelector` to be used in `useQuery`.
549
546
* We want the initial render to already come back with
@@ -989,10 +986,7 @@ export function buildHooks<Definitions extends EndpointDefinitions>({
989
986
}
990
987
991
988
function buildMutationHook ( name : string ) : UseMutation < any > {
992
- return ( {
993
- selectFromResult = defaultMutationStateSelector ,
994
- fixedCacheKey,
995
- } = { } ) => {
989
+ return ( { selectFromResult, fixedCacheKey } = { } ) => {
996
990
const { select, initiate } = api . endpoints [ name ] as ApiEndpointMutation <
997
991
MutationDefinition < any , any , any , any , any > ,
998
992
Definitions
@@ -1019,13 +1013,16 @@ export function buildHooks<Definitions extends EndpointDefinitions>({
1019
1013
)
1020
1014
1021
1015
const { requestId } = promise || { }
1016
+ const initialSelector = useMemo (
1017
+ ( ) => select ( { fixedCacheKey, requestId : promise ?. requestId } ) ,
1018
+ [ fixedCacheKey , promise , select ]
1019
+ )
1022
1020
const mutationSelector = useMemo (
1023
1021
( ) =>
1024
- createSelector (
1025
- [ select ( { fixedCacheKey, requestId : promise ?. requestId } ) ] ,
1026
- selectFromResult
1027
- ) ,
1028
- [ select , promise , selectFromResult , fixedCacheKey ]
1022
+ selectFromResult
1023
+ ? createSelector ( [ initialSelector ] , selectFromResult )
1024
+ : initialSelector ,
1025
+ [ selectFromResult , initialSelector ]
1029
1026
)
1030
1027
1031
1028
const currentState = useSelector ( mutationSelector , shallowEqual )
0 commit comments