Questions:

What is the Difference Between Class and Functional Components?

Interviewers ask this question to assess your understand about the migration of components from Class components to Functional components and the role of hooks in modern React development.

Sample Answer:

Class components use ES6 classes and manages state via “this.stage” and also have access to lifecycle methods like “componentsDidMount”.

Functional components are JS methods that return JSX. Earlier the Functional components were state less but ever since the React 16.8 version, they now have the capability to manage state and side effects via hooks. Functional components offers more optimal performance and code readability over class components and hence it is being the preferred method for creating components.

Related Posts