From a redux tutorial:
const onSavePostClicked = async () => { if (canSave) { try { setAddRequestStatus('pending') await dispatch(addNewPost({ title, content, user: userId })) .unwrap() } catch (err) { console.error('Failed to save the post: ', err) } finally { setAddRequestStatus('idle') } } }
As I understand dispatch(addNewPost({ title, content, user: userId }))
will return a promise like that:
state: "fulfilled"
result: fulfilled action object
and dispatch(addNewPost({ title, content, user: userId })).unwrap()
will also return a promise.
So what is the difference between the promise without and with unwrap
?
state: "fulfilled"
result: ?
createAsyncThunk
method..unwrap()
isn't a native API on Promise's prototype, redux adds this to the promise themselves. See redux-toolkit.js.org/api/… – Mantooth