我要寻找的功能在这里可以使用静态函数语法完美地工作,但是,我喜欢在构造函数本身(即,className.staticFunction () => ...
而不是static staticFunction = () => ...
在类定义本身内)中声明的静态函数。
这是我要引用的代码,我想重构为使用在构造函数/函数上定义的静态函数,而不是static
如下所示的语法。
const higherOrderFunction = another => andAnother => class extends Component {
static functionName = {
test: React.PropTypes.object
};
constructor(props) {
super(props);
}
render() {
return <h1>Hello, World!</h1>;
}
};
export default higherOrderFunction;
a的值与您在没有类的情况下定义class
的构造函数相同function
。所以:
const higherOrderFunction = another => andAnother => Component;
function Component() {}
Component.functionName = () => {
test: React.PropTypes.object
};
Component.prototype.render = () => {
return <h1>Hello, World!</h1>;
}
export default higherOrderFunction;
您可能需要将函数和成员定义包装在函数主体中,以封装和使用任何参数:
const higherOrderFunction = another => andAnother => {
function Component() {}
Component.functionName = () => {
test: React.PropTypes.object
};
Component.prototype.render = () => {
return <h1>Hello, World! {another} and {andAnother}</h1>;
}
return Component;
};
export default higherOrderFunction;
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句