Should unwrap be avoided and how to chain mutations #4835
Replies: 2 comments
-
myMutation(arg).then((res) => {
if (res.data) {
// success
} else {
res.error
// failure
}
})
myMutation(arg).unwrap()
.then((data) => {
// success
}).catch((error) => {
// failure
})They're just two different ways of handling the result of the mutation - both promises will settle when the mutation finishes. |
Beta Was this translation helpful? Give feedback.
-
|
Dispatching a mutation does return a promise. If all you care about is "did it finish", you can just so if you do care "did this mutation actually succeed", then yes, you'd want to As for waiting for the promise for chaining / sequencing purposes: yes, that's why async thunks return a promise to begin with. |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
-
I've used
unwrapin some cases where I have multiple mutations and I want to kick one off after the first one finishes.unwrapallowing me to usePromise.then. I was looking at the docs, when I seeunwrapmentioned it also saysWhich has me wondering if
unwrapis not meant for the case that I'm using it for and if thats true then what would be the "preferred" method of chaining mutations.Beta Was this translation helpful? Give feedback.
All reactions