Functional React VS Class components
2 July, 2022
12
12
0
Contributors
•
•
•
•
•
What is React Component?
•
What are Functional Components?
•
What are Class Components?
Class VS Functional Components
Class Components
1.
Class Component is known as Stateful components because they implement logic and state.
2.
Constructors are used as it needs to store state.
3.
Class component is instantiated and different life cycle method is kept alive and being run and invoked depending on the phase of the class component.
4.
It must have the render() method returning JSX (which is syntactically similar to HTML) and,
5.
A class component requires you to extend from React. Component and create a render function that returns a React element.
Functional Components
1.
It is also known as Stateless components as they simply accept data and display them in some form, and they are mainly responsible for rendering UI.
2.
Constructors are not used in Functional Components.
3.
Functional components run from top to bottom and once the function is returned it cant be kept alive.
4.
There is no render method used in functional components, and
5.
A functional component is just a plain JavaScript pure function that accepts props as an argument and returns a React element(JSX).