Skip to content

Commit

Permalink
Merge pull request #89 from peterferguson/fix-atom-with-mutation-stat…
Browse files Browse the repository at this point in the history
…e-unsubscribe

fix: `atomWithMutationState` should unsubscribe on unmount
  • Loading branch information
kalijonn authored Aug 18, 2024
2 parents 4171f5d + 4a9f618 commit 7d6ee8e
Showing 1 changed file with 2 additions and 1 deletion.
3 changes: 2 additions & 1 deletion src/atomWithMutationState.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,9 +46,10 @@ export const atomWithMutationState = <TResult = MutationState>(

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') {
Expand Down

0 comments on commit 7d6ee8e

Please sign in to comment.