Skip to content

Commit 412727a

Browse files
authored
Merge pull request #326 from firstred/patch-1
2 parents a8d6f1f + 3220e1b commit 412727a

File tree

1 file changed

+13
-0
lines changed

1 file changed

+13
-0
lines changed

docs/usage/usage-with-typescript.md

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,19 @@ export type RootState = ReturnType<typeof store.getState>
6262
export default store
6363
```
6464

65+
If you pass the reducers directly to `configureStore()` and do not define the root reducer explicitly, there is no reference to `rootReducer`.
66+
Instead, you can refer to `store.getState`, in order to get the `State` type.
67+
68+
```typescript
69+
import { configureStore } from '@reduxjs/toolkit'
70+
import rootReducer from './rootReducer'
71+
const store = configureStore({
72+
reducer: rootReducer
73+
})
74+
export type RootState = ReturnType<typeof store.getState>
75+
```
76+
77+
6578
### Getting the `Dispatch` type
6679
6780
If you want to get the `Dispatch` type from your store, you can extract it after creating the store. It is recommended to give the type a different name like `AppDispatch` to prevent confusion, as the type name `Dispatch` is usually overused. You may also find it to be more convenient to export a hook like `useAppDispatch` shown below, then using it wherever you'd call `useDispatch`.

0 commit comments

Comments
 (0)