在React定義組件最簡單的方式是透過JavaScript function,像是
function Welcome(props) { return <h1>Hello, {props.name}</h1>; }
你也可以透過ES6 class syntax去定義組件:
class Welcome extends React.Component { render() { return <h1>Hello, {this.props.name}</h1>; } }
一樣的結果,那有什麼差別?
閱讀全文 在React中Functional與Class Component的差別