Reputation: 919
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,
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?
Upvotes: 8
Views: 4024
Reputation: 3207
According to the docs, there is no difference in terms of performance: https://reactjs.org/docs/hooks-faq.html#are-hooks-slow-because-of-creating-functions-in-render
Upvotes: 1
Reputation: 56
Both functional and class components in React offer the same functionality. You shouldn't miss anything when using any of the approaches and then you shouldn't differ in rendering performances.
In general, you write less code by using a functional component. This will be more understandable by your colleagues
Upvotes: 0
Reputation: 223
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
Upvotes: 2