@@ -541,9 +541,6 @@ export type MutationTrigger<D extends MutationDefinition<any, any, any, any>> =
541541 ( arg : QueryArgFrom < D > ) : MutationActionCreatorResult < D >
542542 }
543543
544- const defaultQueryStateSelector : QueryStateSelector < any , any > = ( x ) => x
545- const defaultMutationStateSelector : MutationStateSelector < any , any > = ( x ) => x
546-
547544/**
548545 * Wrapper around `defaultQueryStateSelector` to be used in `useQuery`.
549546 * We want the initial render to already come back with
@@ -989,10 +986,7 @@ export function buildHooks<Definitions extends EndpointDefinitions>({
989986 }
990987
991988 function buildMutationHook ( name : string ) : UseMutation < any > {
992- return ( {
993- selectFromResult = defaultMutationStateSelector ,
994- fixedCacheKey,
995- } = { } ) => {
989+ return ( { selectFromResult, fixedCacheKey } = { } ) => {
996990 const { select, initiate } = api . endpoints [ name ] as ApiEndpointMutation <
997991 MutationDefinition < any , any , any , any , any > ,
998992 Definitions
@@ -1019,13 +1013,16 @@ export function buildHooks<Definitions extends EndpointDefinitions>({
10191013 )
10201014
10211015 const { requestId } = promise || { }
1016+ const initialSelector = useMemo (
1017+ ( ) => select ( { fixedCacheKey, requestId : promise ?. requestId } ) ,
1018+ [ fixedCacheKey , promise , select ]
1019+ )
10221020 const mutationSelector = useMemo (
10231021 ( ) =>
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 ]
10291026 )
10301027
10311028 const currentState = useSelector ( mutationSelector , shallowEqual )
0 commit comments