Skip to content

Latest commit

 

History

History
49 lines (41 loc) · 1.06 KB

File metadata and controls

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

@Component({
  // ...
})
export class TodosComponent {
  queryClient = inject(QueryClient)

  // When this mutation succeeds, invalidate any queries with the `todos` or `reminders` query key
  mutation = 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