Skip to content

Commit 09a6531

Browse files
committed
- fix incorrect fetch usage
1 parent 4f12a8d commit 09a6531

File tree

1 file changed

+5
-6
lines changed

1 file changed

+5
-6
lines changed

docs/usage/rtk-query/migrating-to-rtk-query.mdx

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -63,13 +63,12 @@ import { RootState } from '../store'
6363
export const fetchPokemonByName = createAsyncThunk<Pokemon, string>(
6464
'pokemon/fetchByName',
6565
async (name, { rejectWithValue }) => {
66-
const response = await fetch(
67-
`https://pokeapi.co/api/v2/pokemon/${name}`
68-
).then((res) => res.json())
66+
const response = await fetch(`https://pokeapi.co/api/v2/pokemon/${name}`)
67+
const data = await response.json()
6968
if (response.status < 200 || response.status >= 300) {
70-
return rejectWithValue(response)
69+
return rejectWithValue(data)
7170
}
72-
return response
71+
return data
7372
}
7473
)
7574
// highlight-end
@@ -450,7 +449,7 @@ Given that we're no longer using that slice any longer, we can remove the import
450449
We can also remove the _entire slice and hook files_ completely!
451450

452451
```diff
453-
- src/services/pokemonSlice.ts (-52 lines)
452+
- src/services/pokemonSlice.ts (-51 lines)
454453
- src/hooks.ts (-34 lines)
455454
```
456455

0 commit comments

Comments
 (0)