Skip to content

Commit dfb0b92

Browse files
authored
Update createAsyncThunk example to handle getState typings
Was helping someone on Discord with an issue related to `getState` typings, and noticed that the example here, despite being in Typescript, didn't include the necessary generic parameters to actually compile.
1 parent 581e171 commit dfb0b92

File tree

1 file changed

+4
-2
lines changed

1 file changed

+4
-2
lines changed

docs/api/createAsyncThunk.mdx

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -513,9 +513,11 @@ const fetchUserById = createAsyncThunk(
513513

514514
```ts no-transpile
515515
import { createAsyncThunk, createSlice } from '@reduxjs/toolkit'
516-
import { userAPI } from './userAPI'
516+
import { userAPI, User } from './userAPI'
517517

518-
const fetchUserById = createAsyncThunk(
518+
const fetchUserById = createAsyncThunk<User, string, {
519+
state: { users: { loading: string, currentRequestId: string } }
520+
}> (
519521
'users/fetchByIdStatus',
520522
async (userId: string, { getState, requestId }) => {
521523
const { currentRequestId, loading } = getState().users

0 commit comments

Comments
 (0)