File tree Expand file tree Collapse file tree 1 file changed +13
-3
lines changed Expand file tree Collapse file tree 1 file changed +13
-3
lines changed Original file line number Diff line number Diff line change @@ -25,23 +25,33 @@ Redux Toolkit's [**RTK Query data fetching API**](../rtk-query/overview.md) is a
2525
2626Sample usage:
2727
28- ``` js {5-11,22-25,30}
28+ ``` ts {5-11,22-25,30}
2929import { createAsyncThunk , createSlice } from ' @reduxjs/toolkit'
3030import { userAPI } from ' ./userAPI'
3131
3232// First, create the thunk
3333const fetchUserById = createAsyncThunk (
3434 ' users/fetchByIdStatus' ,
35- async (userId , thunkAPI ) => {
35+ async (userId : number , thunkAPI ) => {
3636 const response = await userAPI .fetchById (userId )
3737 return response .data
3838 }
3939)
4040
41+ interface UsersState {
42+ entities: []
43+ loading: ' idle' | ' pending' | ' succeeded' | ' failed'
44+ }
45+
46+ const initialState = {
47+ entities: [],
48+ loading: ' idle' ,
49+ } as UsersState
50+
4151// Then, handle actions in your reducers:
4252const usersSlice = createSlice ({
4353 name: ' users' ,
44- initialState: { entities : [], loading : ' idle ' } ,
54+ initialState ,
4555 reducers: {
4656 // standard reducer logic, with auto-generated action types per reducer
4757 },
You can’t perform that action at this time.
0 commit comments