Open History to see the last commit
postTodoMutation = injectMutation(() => ({
mutationFn: postTodo,
}))
import { injectMutation, QueryClient } from '@tanstack/angular-query'
export class TodosComponent {
readonly queryClient = inject(QueryClient)
// When this mutation succeeds, invalidate any queries with the `todos` or `reminders` query key
readonly addTodoMutation = injectMutation(() => ({
mutationFn: addTodo,
onSuccess: () => {
this.queryClient.invalidateQueries({ queryKey: ['todos'] })
this.queryClient.invalidateQueries({ queryKey: ['reminders'] })
},
}))
}
You can wire up your invalidations to happen using any of the callbacks available in the injectMutation function