diff --git a/src/atomWithMutationState.ts b/src/atomWithMutationState.ts index 7c567cc..1ece316 100644 --- a/src/atomWithMutationState.ts +++ b/src/atomWithMutationState.ts @@ -46,9 +46,10 @@ export const atomWithMutationState = ( const mutationCache = queryClient.getMutationCache() resultsAtom.onMount = (set) => { - mutationCache.subscribe(() => { + const unsubscribe = mutationCache.subscribe(() => { set(getResult(getQueryClient(get).getMutationCache(), getOptions(get))) }) + return unsubscribe } }) if (process.env.NODE_ENV !== 'production') {