Skip to content

Commit 1a6cbef

Browse files
committed
docs: root state type with TS and configureStore
1 parent ec0d752 commit 1a6cbef

File tree

1 file changed

+11
-0
lines changed

1 file changed

+11
-0
lines changed

docs/usage/usage-with-typescript.md

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,17 @@ const rootReducer = combineReducers({})
2828
export type RootState = ReturnType<typeof rootReducer>
2929
```
3030
31+
If you pass the reducers directly to `configureStore()` you can get the `State` type from the store instead.
32+
33+
```typescript
34+
import { configureStore } from '@reduxjs/toolkit'
35+
import rootReducer from './rootReducer'
36+
const store = configureStore({
37+
reducer: rootReducer
38+
})
39+
export type RootState = ReturnType<typeof store.getState>
40+
```
41+
3142
### Getting the `Dispatch` type
3243
3344
If you want to get the `Dispatch` type from your store, you can extract it after creating the store.

0 commit comments

Comments
 (0)