@@ -719,11 +719,6 @@ interface InjectedProps {
719719export const withConnectedCount = <BaseProps extends InjectedProps >(
720720 BaseComponent : React .ComponentType <BaseProps >
721721) => {
722- type HocProps = Diff <BaseProps , InjectedProps > & {
723- // here you can extend hoc with new props
724- initialCount? : number ;
725- };
726-
727722 const mapStateToProps = (state : RootState ) => ({
728723 count: countersSelectors .getReduxCounter (state .counters ),
729724 });
@@ -732,18 +727,24 @@ export const withConnectedCount = <BaseProps extends InjectedProps>(
732727 onIncrement: countersActions .increment ,
733728 };
734729
735- class Hoc extends React .Component <InjectedProps > {
730+ type HocProps = ReturnType <typeof mapStateToProps > &
731+ typeof dispatchProps & {
732+ // here you can extend ConnectedHoc with new props
733+ overrideCount? : number ;
734+ };
735+
736+ class Hoc extends React .Component <HocProps > {
736737 // Enhance component name for debugging and React-Dev-Tools
737738 static displayName = ` withConnectedCount(${BaseComponent .name }) ` ;
738739 // reference to original wrapped component
739740 static readonly WrappedComponent = BaseComponent ;
740741
741742 render() {
742- const { count, onIncrement, ... restProps } = this .props ;
743+ const { count, onIncrement, overrideCount, ... restProps } = this .props ;
743744
744745 return (
745746 <BaseComponent
746- count = { count } // injected
747+ count = { overrideCount || count } // injected
747748 onIncrement = { onIncrement } // injected
748749 { ... (restProps as BaseProps )}
749750 />
@@ -754,7 +755,7 @@ export const withConnectedCount = <BaseProps extends InjectedProps>(
754755 const ConnectedHoc = connect <
755756 ReturnType < typeof mapStateToProps > ,
756757 typeof dispatchProps , // use "undefined" if NOT using dispatchProps
757- HocProps ,
758+ Diff < BaseProps , InjectedProps > ,
758759 RootState
759760 > (
760761 mapStateToProps ,
@@ -776,7 +777,7 @@ import { FCCounter } from '../components';
776777const FCCounterWithConnectedCount = withConnectedCount (FCCounter );
777778
778779export default () => (
779- <FCCounterWithConnectedCount initialCount = {5 } label = {' FCCounterWithState' } />
780+ <FCCounterWithConnectedCount overrideCount = {5 } label = {' FCCounterWithState' } />
780781);
781782
782783` ` `
@@ -1262,6 +1263,7 @@ export default store;
12621263A solution below is using a simple factory function to automate the creation of type-safe action creators. The goal is to decrease maintenance effort and reduce code repetition of type annotations for actions and creators. The result is completely typesafe action-creators and their actions.
12631264
12641265` ` ` tsx
1266+ /* eslint-disable */
12651267import { action } from ' typesafe-actions' ;
12661268
12671269import { ADD , INCREMENT } from ' ./constants' ;
0 commit comments