我有一个简单的react组件,其中包含网格的基本逻辑
class BaseGrid extends Component<IBaseGridProps, IBaseGridState> {
//lot's of class members here
}
//maping state to props and definig action creators
export default connect<any, any, any>(mapStateToProps, actionCreators)(BaseGrid );
我打算将其用作PivotGrid
等其他组件的基类。
但是当我尝试在子类中使用任何超级方法时,
class PivotGrid extends BaseGrid {
//lot's of class members here
private doSomeStuff() {
super.invokeSuperMethod(); // <--- Got error here! :(
}
}
我收到一个错误Cannot invoke an object which is possibly 'undefined'. TS2722
。仅导出基类本身(不使用connect)可以正常工作。
在基类中使用redux connect
的正确方法是什么?