Vishal Yelve
What are the differences between functional and class components?

React JS Interview Question
What are the differences between functional and class
components?

By Vishal Yelve in React on Jan 13 2023
  • Tuhin Paul
    Feb, 2023 22

    In React, there are two types of components: functional and class components. Here are the differences between them:

    Functional Components:

    1. Definition:
      Functional components are JavaScript functions that take in props as input and return a React element.

    2. State:
      Functional components do not have state. This means that they cannot store data or update it in response to user events.

    3. Lifecycle methods:
      Functional components do not have lifecycle methods. This means that they cannot perform actions when the component mounts, updates, or unmounts.

    4. Performance:
      Functional components are generally faster and less memory-intensive than class components, since they do not have a lot of the overhead associated with class components.

    Class Components:

    1. Definition:
      Class components are ES6 classes that extend the React.Component class. They define a render() method that returns a React element.

    2. State:
      Class components have state, which allows them to store and update data in response to user events.

    3. Lifecycle methods:
      Class components have lifecycle methods, which allow them to perform actions when the component mounts, updates, or unmounts.

    4. Performance:
      Class components are generally slower and more memory-intensive than functional components, since they have a lot of the overhead associated with class inheritance and the React.Component class.

    • 0


Most Popular Job Functions


MOST LIKED QUESTIONS