Files
upstream-tanstack-query/docs/framework/angular/guides/invalidations-from-mutations.md
upstream-mirror 3a013ccdfe
Some checks failed
autofix.ci / autofix (push) Failing after 4s
Release / Release (push) Has been skipped
GitHub Actions Security Analysis / Run zizmor (push) Failing after 2s
snapshot of https://github.com/TanStack/query.git (main, 2026-09-16; blobs > 131072B omitted)
2026-09-16 01:13:08 +05:00

1.0 KiB

id, title, ref, replace
id title ref replace
invalidations-from-mutations Invalidations from Mutations docs/framework/react/guides/invalidations-from-mutations.md
useMutation hook
injectMutation function
postTodoMutation = injectMutation(() => ({
  mutationFn: postTodo,
}))
import {
  injectMutation,
  QueryClient,
} from '@tanstack/angular-query-experimental'

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