@@ -13,11 +13,6 @@ interface InjectedProps {
1313export const withConnectedCount = < BaseProps extends InjectedProps > (
1414 BaseComponent : React . ComponentType < BaseProps >
1515) => {
16- type HocProps = Diff < BaseProps , InjectedProps > & {
17- // here you can extend hoc with new props
18- initialCount ?: number ;
19- } ;
20-
2116 const mapStateToProps = ( state : RootState ) => ( {
2217 count : countersSelectors . getReduxCounter ( state . counters ) ,
2318 } ) ;
@@ -26,18 +21,24 @@ export const withConnectedCount = <BaseProps extends InjectedProps>(
2621 onIncrement : countersActions . increment ,
2722 } ;
2823
29- class Hoc extends React . Component < InjectedProps > {
24+ type HocProps = ReturnType < typeof mapStateToProps > &
25+ typeof dispatchProps & {
26+ // here you can extend ConnectedHoc with new props
27+ overrideCount ?: number ;
28+ } ;
29+
30+ class Hoc extends React . Component < HocProps > {
3031 // Enhance component name for debugging and React-Dev-Tools
3132 static displayName = `withConnectedCount(${ BaseComponent . name } )` ;
3233 // reference to original wrapped component
3334 static readonly WrappedComponent = BaseComponent ;
3435
3536 render ( ) {
36- const { count, onIncrement, ...restProps } = this . props ;
37+ const { count, onIncrement, overrideCount , ...restProps } = this . props ;
3738
3839 return (
3940 < BaseComponent
40- count = { count } // injected
41+ count = { overrideCount || count } // injected
4142 onIncrement = { onIncrement } // injected
4243 { ...( restProps as BaseProps ) }
4344 />
@@ -47,8 +48,8 @@ export const withConnectedCount = <BaseProps extends InjectedProps>(
4748
4849 const ConnectedHoc = connect <
4950 ReturnType < typeof mapStateToProps > ,
50- typeof dispatchProps ,
51- HocProps ,
51+ typeof dispatchProps , // use "undefined" if NOT using dispatchProps
52+ Diff < BaseProps , InjectedProps > ,
5253 RootState
5354 > (
5455 mapStateToProps ,
0 commit comments