Skip to content
Source
Sign inSign up
TanStack/query

feat(query-core): add context to mutationfn & mutation callbacks #9615

Mergedjoshuaellis(GitHub profile, opens in a new tab)merged 11 commits intomain fromrefs/pull/9615/headmerged by TkDodo View on GitHub

Showing 50 changed files with 52 additions and 52 deletions (loading 47).

x
0 of 50 viewed, 50 left
24 additions and 24 deletionsdocs/framework/angular/guides/mutations.mdModified
View file
@@ -89,20 +89,20 @@
```ts
mutation = injectMutation(() => ({
mutationFn: addTodo,
- onMutate: (variables) => {
+ onMutate: (variables, context) => {
// A mutation is about to happen!
​
- // Optionally return a context containing data to use when for example rolling back
+ // Optionally return a result containing data to use when for example rolling back
return { id: 1 }
},
- onError: (error, variables, context) => {
+ onError: (error, variables, onMutateResult, context) => {
// An error happened!
- console.log(`rolling back optimistic update with id ${context.id}`)
+ console.log(`rolling back optimistic update with id ${onMutateResult.id}`)
- onSuccess: (data, variables, context) => {
+ onSuccess: (data, variables, onMutateResult, context) => {
// Boom baby!
- onSettled: (data, error, variables, context) => {
+ onSettled: (data, error, variables, onMutateResult, context) => {
// Error or success... doesn't matter!