Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Functional components have better performance than Class components?

Before react hooks, we called functional components to stateless components. At that time it was really faster than class components but what about now?

Since we have react hooks, stateless components are no longer precise. Does the functional components are faster than class components which runs same functions?

e.g. In functional components,

  • I can handle state variables by using useState hook.
  • useEffect can represent componentDidMount, componentWillReceiveProps or some other lifecycle methods in Class component.
  • ... ... ...

We have many other hook functions but which hooks will make my class components faster or lightweight?

like image 763
Smart Solutions Avatar asked Nov 07 '22 04:11

Smart Solutions


1 Answers

Using React hooks will definitely reduce the amount of code you have to write in comparison to class based components.They are much easier to read and debug. In sense of Performance , in class components :

Cleaning up and applying the effect after every render is task heavy, and we might right run into issues or bugs.

so overall Hooks is a better option. source

like image 173
Kimia Khakzad Avatar answered Nov 13 '22 22:11

Kimia Khakzad