Component: độc lập và tái sử dụng.
Có 2 kiểu: Functional component và Class component

Functional component

Functional component là function Javascript trả về 1 React element, có thể nhận props làm tham số nếu cần.

function Welcome(props) {
    return <h1>Hello, {props.name}</h1>; 
}

Class component

Class component phức tạp hơn Functional component. Nó là một class kết thừ từ React.Component, có thể nhận props trong hàm khởi tạo nếu cần và phải có hàm render() trả về 1 React element hoặc NULL.

class Welcome extends React.Component {
     render() {
         return <h1>Hello, {this.props.name}</h1>;
     } 
}

Leave a Reply

Your email address will not be published. Required fields are marked *