File: MutationCache.md | Updated: 11/15/2025
Search...
+ K
Auto
Docs Examples GitHub Contributors
Docs Examples GitHub Contributors
Docs Examples GitHub Contributors
Docs Examples Github Contributors
Docs Examples Github Contributors
Docs Examples Github Contributors
Docs Examples Github Contributors
Docs Examples Github Contributors
Maintainers Partners Support Learn StatsBETA Discord Merch Blog GitHub Ethos Brand Guide
Documentation
Framework
React
Version
Latest
Search...
+ K
Menu
Getting Started
Guides & Concepts
API Reference
ESLint
Examples
Plugins
Framework
React
Version
Latest
Menu
Getting Started
Guides & Concepts
API Reference
ESLint
Examples
Plugins
On this page
Copy Markdown
The MutationCache is the storage for mutations.
Normally, you will not interact with the MutationCache directly and instead use the QueryClient.
tsx
import { MutationCache } from '@tanstack/react-query'
const mutationCache = new MutationCache({
onError: (error) => {
console.log(error)
},
onSuccess: (data) => {
console.log(data)
},
})
import { MutationCache } from '@tanstack/react-query'
const mutationCache = new MutationCache({
onError: (error) => {
console.log(error)
},
onSuccess: (data) => {
console.log(data)
},
})
Its available methods are:
Options
Global callbacks
----------------
The onError, onSuccess, onSettled and onMutate callbacks on the MutationCache can be used to handle these events on a global level. They are different to defaultOptions provided to the QueryClient because:
mutationCache.getAll
--------------------
getAll returns all mutations within the cache.
Note: This is not typically needed for most applications, but can come in handy when needing more information about a mutation in rare scenarios
tsx
const mutations = mutationCache.getAll()
const mutations = mutationCache.getAll()
Returns
mutationCache.subscribe
-----------------------
The subscribe method can be used to subscribe to the mutation cache as a whole and be informed of safe/known updates to the cache like mutation states changing or mutations being updated, added or removed.
tsx
const callback = (event) => {
console.log(event.type, event.mutation)
}
const unsubscribe = mutationCache.subscribe(callback)
const callback = (event) => {
console.log(event.type, event.mutation)
}
const unsubscribe = mutationCache.subscribe(callback)
Options
Returns
mutationCache.clear
-------------------
The clear method can be used to clear the cache entirely and start fresh.
tsx
mutationCache.clear()
mutationCache.clear()
[###### Want to Skip the Docs?
Query.gg - The Official React Query Course
\
“If you’re serious about *really* understanding React Query, there’s no better way than with query.gg”—Tanner Linsley
Learn More](https://query.gg/?s=tanstack)
