Skip to content

Commit

Permalink
⚡️ Make useMutation reset use batched updates
Browse files Browse the repository at this point in the history
  • Loading branch information
Shrugsy committed Oct 16, 2021
1 parent 8b62c14 commit f2c3606
Showing 1 changed file with 13 additions and 11 deletions.
24 changes: 13 additions & 11 deletions packages/toolkit/src/query/react/buildHooks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -825,17 +825,19 @@ export function buildHooks<Definitions extends EndpointDefinitions>({
const originalArgs =
fixedCacheKey == null ? promise?.arg.originalArgs : undefined
const reset = useCallback(() => {
if (promise) {
setPromise(undefined)
}
if (fixedCacheKey) {
dispatch(
api.internalActions.removeMutationResult({
requestId,
fixedCacheKey,
})
)
}
batch(() => {
if (promise) {
setPromise(undefined)
}
if (fixedCacheKey) {
dispatch(
api.internalActions.removeMutationResult({
requestId,
fixedCacheKey,
})
)
}
})
}, [dispatch, fixedCacheKey, promise, requestId])
const finalState = useMemo(
() => ({ ...currentState, originalArgs, reset }),
Expand Down

0 comments on commit f2c3606

Please sign in to comment.