diff --git a/src/useMutation.js b/src/useMutation.js index 3d9f183d402..986ec8f3c87 100644 --- a/src/useMutation.js +++ b/src/useMutation.js @@ -64,12 +64,15 @@ export function useMutation( ...useConfigContext(), ...config, }) + + const getStatus = useGetLatest(state.status) const mutate = React.useCallback( async (variables, options = {}) => { - if (![statusIdle, statusSuccess, statusError].includes(state.status)) { + if (![statusIdle, statusSuccess, statusError].includes(getStatus())) { return } + dispatch({ type: actionMutate }) const resolvedOptions = { @@ -95,7 +98,7 @@ export function useMutation( } } }, - [getConfig, getMutationFn, state.status] + [getConfig, getMutationFn, getStatus] ) const reset = React.useCallback(() => dispatch({ type: actionReset }), [])