Could anyone can explain in detail the difference between functional component and class component in ReactJS?
When we use a functional component and when we use the class component?
Personally, I found the functional component easier to understand compared to the class component, although this might be different for a developer from object-oriented programming like Java. The class component uses ES6 class syntax, and it extends React components with a render method that returns React elements.
In the case of class components, when the state of the component is changed then the render method is called. Whereas, function components render the interface whenever the props are changed.
Functional component are much easier to read and test because they are plain JavaScript functions without state or lifecycle-hooks. You end up with less code. They help you to use best practices.
A functional component is basically a JavaScript function which returns a React element. Its accepts props as argument and returns valid JSX
Class Components are more complex than functional components including constructors, life-cycle methods, render( ) function and state (data) management. Class components are ES6 classes.
For more click here
See this picture. I am too much late but i will help the others.
Source of Image is Udemy Course
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With