Question d’entretien chez LoyaltyLion

What are the differences between Class components and Functional components in React? When do you use them?

Réponse à la question d'entretien

Utilisateur anonyme

14 mai 2020

Functional components are basic JavaScript functions. These are typically arrow functions but can also be created with the regular function keyword.Sometimes referred to as “dumb” or “stateless” components as they simply accept data and display them in some form; that is they are mainly responsible for rendering UI. React lifecycle methods (for example, componentDidMount) cannot be used in functional components. There is no render method used in functional components. Class components make use of ES6 class and extend the Component class in React. Sometimes called “smart” or “stateful” components as they tend to implement logic and state. React lifecycle methods can be used inside class components (for example, componentDidMount). You pass props down to class components and access them with this.props