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 {
}
的問題是:有沒有什麼區別,是使用的語法與功能的關鍵字有什麼好處?