Skip to content

Commit ba8c911

Browse files
authored
Unwrap result of async thunk so error throws to calling component (#861)
1 parent f00c11e commit ba8c911

File tree

1 file changed

+2
-2
lines changed

1 file changed

+2
-2
lines changed

docs/api/createAsyncThunk.mdx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -437,7 +437,7 @@ const fetchUserById = createAsyncThunk(
437437
- Requesting a user by ID, with loading state, and only one request at a time:
438438

439439
```js
440-
import { createAsyncThunk, createSlice } from '@reduxjs/toolkit'
440+
import { createAsyncThunk, createSlice, unwrapResult } from '@reduxjs/toolkit'
441441
import { userAPI } from './userAPI'
442442

443443
const fetchUserById = createAsyncThunk(
@@ -494,7 +494,7 @@ const UsersComponent = () => {
494494
const fetchOneUser = async userId => {
495495
try {
496496
const resultAction = await dispatch(fetchUserById(userId))
497-
const user = resultAction.payload
497+
const user = unwrapResult(resultAction)
498498
showToast('success', `Fetched ${user.name}`)
499499
} catch (err) {
500500
showToast('error', `Fetch failed: ${err.message}`)

0 commit comments

Comments
 (0)