Difference between class component and functional component

 

                 Class component

 

Functional component

 Class-based Components uses ES6 class syntax. Functional Components are simpler comparing to class-based functions.

 

The lifecycle methods can be used. Functional Components mainly focuses on the UI of the application, not on the behavior.
More code to write. Easy to write.
Used for presenting static data. Used for dynamic source of data.
Can’t handle fetching data. Handles any data that might change.
It must have a render() method. It doesn’t have a render() method.
Here,React lifecycle methods (like componentDidMount, etc.) are used React hooks are there to be as a better alternative to the traditional React lifecycle methods.
For e.g:

const [name,SetName]= React.useState(‘ ‘)

For e.g:

constructor(props) {

super(props);

this.state = {name: ‘ ‘}

}

 

In functional components to make them Stateful, Hooks can be easily used. In class component to implement hooks,It requires different syntax.

 

 

Leave a Reply

Your email address will not be published. Required fields are marked *

You May Also Like

What is Prop Drilling ?

We pass a prop with another component with the help of all the components that come between, this method is known as prop drilling. Prop drilling is basically a situation…
View Answer

What is React DOM ?

It is an object which exposes a number of top level APIs to interact with the browser DOM. It provides DOM-specific methods that can be used at the top level…
View Answer

What is Flux ?

It is an application architecture that Facebook makes use of internally for constructing the client-side web application with React . It is a programming concept, where the data is a…
View Answer