I am a bit confused on how to use the value provided from rejectWithValue
I was expecting that in my reducer/rejected reducer I would have access to an error?
{
name
message
code
stack
}
But I am always seeing just a value 'rejected'.
I would like UI to be dependent on the code of the error we are getting but am unsure of how to derive this value when returning rejectWithValue with and error from an async thunk.
Any help appreciated
@stuartflanagan When you use rejectWithValue, the error is returned in the payload.
if the promise resolved with a rejectWithValue(value) return value, dispatch the rejected action with the value passed into action.payload and 'Rejected' as action.error.message
Reference: https://redux-toolkit.js.org/api/createAsyncThunk#return-value
From what I can tell from your description, you'd want to parse the error and return an expected/standardized format.
Thank you for the clarification @msutkowski
Most helpful comment
Thank you for the clarification @msutkowski