Skip to content
Source
Sign inSign up
TanStack/query
Open History to see the last commit

invalidations-from-mutations.md

41 lines1.0 KB

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