DEV Community

Discussion on: How to replicate a React component lifecycle with useEffect

Collapse
 
rleija_ profile image
Ruben • Edited

That's a great question, and your way of thinking of building React components is totally valid.

I think it really comes down to lowering the barrier of entry. I believe that functional programming is a popular choice of programming style because it's easy to write, and to maintain.

4 reasons why someone might want to choose functional type components

1) Classes confuse people
JavaScript classes aren't really like traditional classes. Under the hood JavaScript is still a prototype base language. So all it's quirks still come in ES6.

2) Classes get complex really quickly
Managing state logic through component lifecycles become unmanageable and a mess. Reducing them into small chunks of code is easier to digest.

3) Re-usable state or effect logic between components (worth it)

4) Smaller webpack bundler (I like this one too a lot)

Nonetheless, if you're comfortable with classes and keeping UI components just as simple function components, keep doing that then.