Blog>
Snippets

Instantiating and Configuring MutationCache

Show how to create a new instance of MutationCache in React Query and configure its default options.
import { MutationCache } from 'react-query';
Import MutationCache from react-query.
const mutationCache = new MutationCache({
  onError: (error, variables, context) => {
    // Handle global mutation errors
    console.error(`Mutation error: ${error.message}`, variables);
  },
  onSuccess: (data, variables, context) => {
    // Handle global mutation success
    console.log('Mutation successful', data);
  }
});
Instantiate MutationCache with default options. Here, global error and success handlers are configured to log messages.