Skip to content

Commit 2ac58a1

Browse files
Update useMutation memoization (#166)
* Update useMutation memoization * Update useMutation.js Co-authored-by: Tanner Linsley <[email protected]>
1 parent 1ae462b commit 2ac58a1

File tree

1 file changed

+5
-2
lines changed

1 file changed

+5
-2
lines changed

src/useMutation.js

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -64,12 +64,15 @@ export function useMutation(
6464
...useConfigContext(),
6565
...config,
6666
})
67+
68+
const getStatus = useGetLatest(state.status)
6769

6870
const mutate = React.useCallback(
6971
async (variables, options = {}) => {
70-
if (![statusIdle, statusSuccess, statusError].includes(state.status)) {
72+
if (![statusIdle, statusSuccess, statusError].includes(getStatus())) {
7173
return
7274
}
75+
7376
dispatch({ type: actionMutate })
7477

7578
const resolvedOptions = {
@@ -95,7 +98,7 @@ export function useMutation(
9598
}
9699
}
97100
},
98-
[getConfig, getMutationFn, state.status]
101+
[getConfig, getMutationFn, getStatus]
99102
)
100103

101104
const reset = React.useCallback(() => dispatch({ type: actionReset }), [])

0 commit comments

Comments
 (0)