我有一个组件,我尝试编写(从“compose-function”库导入)如下;
export function MyRoute() {
let MyGridWithData = compose(
withRouter,
withTranslation("translations"),
withMyApi()
)(MyGrid);
return <MyGridWithData />;
}
但是,由于某种原因,我看到以下错误;
TypeError: Object(...) is not a function
错误指出在行上;让 MyGridWithData = compose(...)
此外,虽然 withRouter 和 withTranslation 是标准钩子,但 withMyApi 定义如下(基本上是 HOF);
export function withMyApi() {
// Extra function wrapper
return function(WrappedComponent) {
class MyApiUrls extends React.Component {
constructor(props) {
super(props);
}
render() {
return <WrappedComponent api={this.api} {...this.props} />;
}
}
return MyApiUrls;
};
}