Class component and functional component

What are the differences between a class component and functional component?

1 Like

Basically Functional components are basic JavaScript functions.They are called as stateless components.
Ex :

import React from "react";

const Test = props => (
  <div>
    <h1>Hello, {props.name}</h1>
  </div>
);

export default Test;

Class components make use of ES6 class and extend the Component class in React.

EX :

import React, { Component } from "react";

class Testextends Component {
  constructor(props){
    super(props);
    this.state = {
      myState: true;
    }
  }
  
  render() {
    return (
      <div>
        <h1>Hello World</h1>
      </div>
    );
  }
}

export default Test;
1 Like

Thank you ayye :mechanical_arm: