@@ -106,6 +106,7 @@ I highly recommend to add a bounty to the issue that you're waiting for to incre
106
106
- [ Redux Connected Components] ( #redux-connected-components )
107
107
- [ - Redux connected counter] ( #--redux-connected-counter )
108
108
- [ - Redux connected counter with own props] ( #--redux-connected-counter-with-own-props )
109
+ - [ - Redux connected counter via hooks] ( #--redux-connected-counter-via-hooks )
109
110
- [ - Redux connected counter with ` redux-thunk ` integration] ( #--redux-connected-counter-with-redux-thunk-integration )
110
111
- [ Context] ( #context )
111
112
- [ ThemeContext] ( #themecontext )
@@ -132,6 +133,7 @@ I highly recommend to add a bounty to the issue that you're waiting for to incre
132
133
- [ Selectors with ` reselect ` ] ( #selectors-with-reselect )
133
134
- [ Connect with ` react-redux ` ] ( #connect-with-react-redux )
134
135
- [ Typing connected component] ( #typing-connected-component )
136
+ - [ Typing ` useSelector ` and ` useDispatch ` ] ( #typing-useselector-and-usedispatch )
135
137
- [ Typing connected component with ` redux-thunk ` integration] ( #typing-connected-component-with-redux-thunk-integration )
136
138
- [ Configuration & Dev Tools] ( #configuration--dev-tools )
137
139
- [ Common Npm Scripts] ( #common-npm-scripts )
@@ -874,6 +876,26 @@ export default () => (
874
876
875
877
[⇧ back to top](#table-of-contents)
876
878
879
+ ### - Redux connected counter via hooks
880
+
881
+ ` ` ` tsx
882
+ import * as React from ' react' ;
883
+ import { FCCounter } from ' ../components' ;
884
+ import { increment } from ' ../features/counters/actions' ;
885
+ import { useSelector , useDispatch } from ' ../store/hooks' ;
886
+
887
+ const FCCounterConnectedHooksUsage: React .FC = () => {
888
+ const counter = useSelector (state => state .counters .reduxCounter );
889
+ const dispatch = useDispatch ();
890
+ return <FCCounter label = " Use selector" count = { counter } onIncrement = { () => dispatch (increment ())} />;
891
+ };
892
+
893
+ export default FCCounterConnectedHooksUsage;
894
+
895
+ ` ` `
896
+
897
+ [⇧ back to top](#table-of-contents)
898
+
877
899
### - Redux connected counter with ` redux - thunk ` integration
878
900
879
901
` ` ` tsx
@@ -1703,6 +1725,27 @@ const mapDispatchToProps = (dispatch: Dispatch<MyTypes.RootAction>) =>
1703
1725
1704
1726
` ` `
1705
1727
1728
+ [⇧ back to top](#table-of-contents)
1729
+
1730
+ ### Typing ` useSelector ` and ` useDispatch `
1731
+
1732
+ ` ` ` tsx
1733
+ import { Dispatch } from ' redux' ;
1734
+ import {
1735
+ TypedUseSelectorHook ,
1736
+ useSelector as useGenericSelector ,
1737
+ useDispatch as useGenericDispatch
1738
+ } from ' react-redux' ;
1739
+ import { RootState , RootAction } from ' MyTypes' ;
1740
+
1741
+ export const useSelector: TypedUseSelectorHook <RootState > = useGenericSelector ;
1742
+
1743
+ export const useDispatch: () => Dispatch <RootAction > = useGenericDispatch ;
1744
+
1745
+ ` ` `
1746
+
1747
+ [⇧ back to top](#table-of-contents)
1748
+
1706
1749
### Typing connected component with ` redux - thunk ` integration
1707
1750
1708
1751
*__NOTE__: When using thunk action creators you need to use ` bindActionCreators ` . Only this way you can get corrected dispatch props type signature like below.*
0 commit comments