DEV Community

Discussion on: When to use Class Component and Function Component??

Collapse
 
tsolan profile image
Eugene

Easier to write, no 'this' messing, less lines, cleaner and much more readeble code.
I think, it's enough.

Collapse
 
ozzythegiant profile image
Oziel Perez

But harder to read, leads to messier components, and most devs end up with giant function component files. All these hooks are just an excuse to not understand how this works. State is going to be commited to memory no matter what, so I see no reason to use function components when should have just continued using class components.

Thread Thread
 
tsolan profile image
Eugene

Is it a joke or you have never really seen both of them? About hooks… it made me laugh. Feelings like someone came from Java and trying to use oop everywhere else without understanding the reasons.

Thread Thread
 
ozzythegiant profile image
Oziel Perez

I use React on a regular basis and have used it since v15. Hooks we're adopted by everyone because they can't do OOP for squat. Hooks have been a disservice to web development and have littered code bases with spaghetti code. I see no benefit to hooks other than being a fake class. Should have just stuck with classes. Nice assumption that you think I come from Java. I hate the Java ecosystem because they over engineer all their OOP code. My stance is that so many devs can't organize their code at all, and hooks just exacerbated the problem.

Thread Thread
 
tsolan profile image
Eugene • Edited

It doesn’t really matter what is going on behind the scenes and how much code hooks require for their realisation. Since there are no native classes in js but syntactic sugar over functions, it’s strange to hear about spaghetti code. The only purpose of libraries/frameworks such as React - to abstract away many sophisticated details and simplify development, not vice versa, and function components are just the next step to improve that.

Thread Thread
 
ozzythegiant profile image
Oziel Perez

Disagreed. So many devs write messy code with functions. They don't understand that there needs to be separation of concerns and that functions need to be small. Plus, class components have superior readability because of the strict OOP conventions. The best functions are pure, easily tested, but because of UI being rendered as a function, side-effects make the function unpure.

Some comments have been hidden by the post's author - find out more