From dcc2797d81c94193adfb700cd6c979e2d06e56df Mon Sep 17 00:00:00 2001 From: Oliver Winter Date: Thu, 27 Feb 2020 21:12:37 +0100 Subject: [PATCH 1/2] Update useMutation memoization --- src/useMutation.js | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/src/useMutation.js b/src/useMutation.js index 3d9f183d40..301955180f 100644 --- a/src/useMutation.js +++ b/src/useMutation.js @@ -67,9 +67,6 @@ export function useMutation( const mutate = React.useCallback( async (variables, options = {}) => { - if (![statusIdle, statusSuccess, statusError].includes(state.status)) { - return - } dispatch({ type: actionMutate }) const resolvedOptions = { @@ -95,7 +92,7 @@ export function useMutation( } } }, - [getConfig, getMutationFn, state.status] + [getConfig, getMutationFn] ) const reset = React.useCallback(() => dispatch({ type: actionReset }), []) From 3922bf883bded339f9cbb260f47fe8f3fdf0420c Mon Sep 17 00:00:00 2001 From: Tanner Linsley Date: Thu, 27 Feb 2020 13:35:40 -0700 Subject: [PATCH 2/2] Update useMutation.js --- src/useMutation.js | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/src/useMutation.js b/src/useMutation.js index 301955180f..986ec8f3c8 100644 --- a/src/useMutation.js +++ b/src/useMutation.js @@ -64,9 +64,15 @@ export function useMutation( ...useConfigContext(), ...config, }) + + const getStatus = useGetLatest(state.status) const mutate = React.useCallback( async (variables, options = {}) => { + if (![statusIdle, statusSuccess, statusError].includes(getStatus())) { + return + } + dispatch({ type: actionMutate }) const resolvedOptions = { @@ -92,7 +98,7 @@ export function useMutation( } } }, - [getConfig, getMutationFn] + [getConfig, getMutationFn, getStatus] ) const reset = React.useCallback(() => dispatch({ type: actionReset }), [])