0
大多数示例在显示如何创建高阶组件时都使用function关键字。高级组件:函数关键字与箭头函数
从下面的例子阵营文档:
function logProps(WrappedComponent) {
return class extends React.Component {
componentWillReceiveProps(nextProps) {
console.log('Current props: ', this.props);
console.log('Next props: ', nextProps);
}
render() {
// Wraps the input component in a container, without mutating it. Good!
return <WrappedComponent {...this.props} />;
}
}
}
在我工作的地方,我们使用打字稿的地方,我们有TS-皮棉规则,不要使用function关键字。
高阶组件的JS所以版本看起来就像是这样的:
export const collapse = (options) =>
(Trigger) =>
class C extends React.Component {
}
的问题是:有没有什么区别,是使用的语法与功能的关键字有什么好处?