Open History to see the last commit
1---
2id: invalidations-from-mutations
3title: Invalidations from Mutations
4ref: docs/react/guides/invalidations-from-mutations.md
5replace: { 'useMutation': 'injectMutation', 'hook': 'function' }
6---
7β
8[//]: # 'Example'
9β
10```ts
11class TodoItemComponent {
12 mutation = injectMutation(() => ({
13 mutationFn: postTodo,
14 }))
15}
16```
17β
18[//]: # 'Example'
19[//]: # 'Example2'
20β
21```ts
22import { injectMutation } from '@tanstack/angular-query-experimental'
23β
24export class TodosComponent {
25 queryClient = injectQueryClient()
26β
27 // When this mutation succeeds, invalidate any queries with the `todos` or `reminders` query key
28 mutation = injectMutation((client) => ({
29 mutationFn: addTodo,
30 onSuccess: () => {
31 client.invalidateQueries({ queryKey: ['todos'] })
32 client.invalidateQueries({ queryKey: ['reminders'] })
33β
34 // OR use the queryClient that is injected into the component
35 // this.queryClient.invalidateQueries({ queryKey: ['todos'] })
36 },
37 }))
38}
39```
40β
41[//]: # 'Example2'
42β
43You can wire up your invalidations to happen using any of the callbacks available in the [`injectMutation` function](../guides/mutations)