@@ -13,11 +13,6 @@ interface InjectedProps {
13
13
export const withConnectedCount = < BaseProps extends InjectedProps > (
14
14
BaseComponent : React . ComponentType < BaseProps >
15
15
) => {
16
- type HocProps = Diff < BaseProps , InjectedProps > & {
17
- // here you can extend hoc with new props
18
- initialCount ?: number ;
19
- } ;
20
-
21
16
const mapStateToProps = ( state : RootState ) => ( {
22
17
count : countersSelectors . getReduxCounter ( state . counters ) ,
23
18
} ) ;
@@ -26,18 +21,24 @@ export const withConnectedCount = <BaseProps extends InjectedProps>(
26
21
onIncrement : countersActions . increment ,
27
22
} ;
28
23
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 > {
30
31
// Enhance component name for debugging and React-Dev-Tools
31
32
static displayName = `withConnectedCount(${ BaseComponent . name } )` ;
32
33
// reference to original wrapped component
33
34
static readonly WrappedComponent = BaseComponent ;
34
35
35
36
render ( ) {
36
- const { count, onIncrement, ...restProps } = this . props ;
37
+ const { count, onIncrement, overrideCount , ...restProps } = this . props ;
37
38
38
39
return (
39
40
< BaseComponent
40
- count = { count } // injected
41
+ count = { overrideCount || count } // injected
41
42
onIncrement = { onIncrement } // injected
42
43
{ ...( restProps as BaseProps ) }
43
44
/>
@@ -47,8 +48,8 @@ export const withConnectedCount = <BaseProps extends InjectedProps>(
47
48
48
49
const ConnectedHoc = connect <
49
50
ReturnType < typeof mapStateToProps > ,
50
- typeof dispatchProps ,
51
- HocProps ,
51
+ typeof dispatchProps , // use "undefined" if NOT using dispatchProps
52
+ Diff < BaseProps , InjectedProps > ,
52
53
RootState
53
54
> (
54
55
mapStateToProps ,
0 commit comments