@@ -106,6 +106,7 @@ I highly recommend to add a bounty to the issue that you're waiting for to incre
106106 - [ Redux Connected Components] ( #redux-connected-components )
107107 - [ - Redux connected counter] ( #--redux-connected-counter )
108108 - [ - Redux connected counter with own props] ( #--redux-connected-counter-with-own-props )
109+ - [ - Redux connected counter via hooks] ( #--redux-connected-counter-via-hooks )
109110 - [ - Redux connected counter with ` redux-thunk ` integration] ( #--redux-connected-counter-with-redux-thunk-integration )
110111 - [ Context] ( #context )
111112 - [ ThemeContext] ( #themecontext )
@@ -132,6 +133,7 @@ I highly recommend to add a bounty to the issue that you're waiting for to incre
132133 - [ Selectors with ` reselect ` ] ( #selectors-with-reselect )
133134 - [ Connect with ` react-redux ` ] ( #connect-with-react-redux )
134135 - [ Typing connected component] ( #typing-connected-component )
136+ - [ Typing ` useSelector ` and ` useDispatch ` ] ( #typing-useselector-and-usedispatch )
135137 - [ Typing connected component with ` redux-thunk ` integration] ( #typing-connected-component-with-redux-thunk-integration )
136138- [ Configuration & Dev Tools] ( #configuration--dev-tools )
137139 - [ Common Npm Scripts] ( #common-npm-scripts )
@@ -874,6 +876,26 @@ export default () => (
874876
875877[⇧ back to top](#table-of-contents)
876878
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+
877899### - Redux connected counter with ` redux - thunk ` integration
878900
879901` ` ` tsx
@@ -1703,6 +1725,27 @@ const mapDispatchToProps = (dispatch: Dispatch<MyTypes.RootAction>) =>
17031725
17041726` ` `
17051727
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+
17061749### Typing connected component with ` redux - thunk ` integration
17071750
17081751*__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