TanStackT
TanStack2y ago
2 replies
systematic-tan

How to setup automatic invalidation after mutation

I want to setup a remix like automatic invalidation.
I saw this post from TkDodo: https://tkdodo.eu/blog/automatic-query-invalidation-after-mutations#the-global-cache-callbacks
But I am having trouble understanding how is solution is possible.

const queryClient = new QueryClient({
  mutationCache: new MutationCache({
    onSuccess: () => {
      queryClient.invalidateQueries()
    },
  }),
})


We cannot use
queryClient
inside its own declaration.
Do I need to create a second one above juste to configure correctly the MutationCache ?

Thx.
Even though there is nothing built into React Query, it doesn't need a lot of code to implement automatic query invalidation in user-land thanks to the global cache callbacks.
Automatic Query Invalidation after Mutations
Was this page helpful?