Skip to content

Commit 7eee197

Browse files
authored
Add info about useAppDispatch to docs (#1651)
1 parent c4d81af commit 7eee197

File tree

1 file changed

+5
-0
lines changed

1 file changed

+5
-0
lines changed

docs/using-react-redux/static-types.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,11 @@ export type AppDispatch = typeof store.dispatch
8080
// MyComponent.tsx
8181
const dispatch: AppDispatch = useDispatch()
8282
```
83+
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`:
84+
```ts
85+
export type AppDispatch = typeof store.dispatch
86+
export const useAppDispatch = () => useDispatch<AppDispatch>() // Export a hook that can be reused to resolve types
87+
```
8388

8489
### Typing the `connect` higher order component
8590

0 commit comments

Comments
 (0)