You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: docs/api/createAsyncThunk.md
+21-16Lines changed: 21 additions & 16 deletions
Original file line number
Diff line number
Diff line change
@@ -64,7 +64,7 @@ For example, a `type` argument of `'users/requestStatus'` will generate these ac
64
64
65
65
### `payloadCreator`
66
66
67
-
A callback function that should return a promise containing the result of some asynchronous logic. It may also return a value synchronously. If there is an error, it should return a rejected promise containing one of the following: an `Error` instance, a plain value such as a descriptive error message, or a manually rejected error with a defined payload.
67
+
A callback function that should return a promise containing the result of some asynchronous logic. It may also return a value synchronously. If there is an error, it should either return a rejected promise containing an `Error` instance or a plain value such as a descriptive error message or otherwise a resolved promise with a `RejectWithValue` argument as returned by the `thunkApi.rejectWithValue` function.
68
68
69
69
The `payloadCreator` function can contain whatever logic you need to calculate an appropriate result. This could include a standard AJAX data fetch request, multiple AJAX calls with the results combined into a final value, interactions with React Native `AsyncStorage`, and so on.
70
70
@@ -91,7 +91,7 @@ When dispatched, the thunk will:
91
91
- call the `payloadCreator` callback and wait for the returned promise to settle
92
92
- when the promise settles:
93
93
- if the promise resolved successfully, dispatch the `fulfilled` action with the promise value as `action.payload`
94
-
- if the promise resolved successfully or failed, but was returned with `rejectWithValue(value)`, dispatch the `rejected` action with the value passed into `action.payload` and 'Rejected' as `action.error.message`
94
+
- 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`
95
95
- if the promise failed and was not handled with `rejectWithValue`, dispatch the `rejected` action with a serialized version of the error value as `action.error`
96
96
- Return a fulfilled promise containing the final dispatched action (either the `fulfilled` or `rejected` action object)
97
97
@@ -391,8 +391,9 @@ import { userAPI } from './userAPI'
// This is assuming the api returned a 400 error with a body of { errorMessage: 'Validation errors', field_errors: [{ field_name: 'Should be a string' }]}
444
-
setErrors(resultAction.payload.field_errors)
444
+
// This is assuming the api returned a 400 error with a body of { errorMessage: 'Validation errors', field_errors: { field_name: 'Should be a string' }}
0 commit comments