How to create components in React


There are two ways to create a component in React js.

  1. Class components: with extending React.Component you can create a component.

    class Name extends React.Component {
      render() {
        return <h1>{`Hello, ${this.props.message}`}</h1>
      }
    }
  2. Function components: This is the easy way to create a component, props object contains the data.

    function Name({ message }) {
      return <h1>{`Hello, ${message}`}</h1>
    
    }