DEV Community

[Comment from a deleted post]
Collapse
 
mangor1no profile image
Info Comment hidden by post author - thread only visible in this permalink
Mangor1no

Your comparison doesn't even relevant to each other. If you want, I can write that class component 6 lines less than your codes above. The main different points between class component and functional component using hooks is:

  1. Class component give you power to control your states/props with lifecycle and "this" (and yes, componentDidMount and componentDidUpdate are not equal to useEffect).
  2. Methods inside functional component will be re-declaring if that component is re-render, which affect your web application performance.
  3. Class component has steep learning curve. Functional component heading to an easy development experience for newcomer. For fast coding I will recommend using functional component. But if you need advance ways to approach the solution, for example, control animation in React Native app, or handle difficult logic, use class component.