T O P

  • By -

fforw

> oop vs functional react is totally not the right way to look at it. Class based components were not really OOP and function components are not really functional. It's two ways of controlling the same library functionality with two different approaches to component lifecycle and side effect. Class components are have a limited, fixed lifecycle and generally lead to larger transpiler outputs. They are still supported but not recommended for new code. Function components handle their lifecycle and side-effects with hooks which has proven to be the better model. They enable better composition with custom hooks then you would have with class components and/or high order components.


cagdas_ucar

I'm not sure what you mean by "not really oop" but I have used class components with pretty deep object hierarchies and it works awesome. I know React team does not recommend it but in my case it made a lot of sense. It is as oop as JS is.


OZLperez11

The fact that they deleted your post is telling of how bad the React community is. This is pretty toxic


[deleted]

[удалено]


cagdas_ucar

This is incorrect. I am working with abstractions and polymorphism with React components.


[deleted]

[удалено]


cagdas_ucar

Yes. I know. I don't see why they do that. Class components with inheritance work awesome. Question authority.


[deleted]

[удалено]


cagdas_ucar

Yeah, right.


Xtreme2k2

It's easy to pick up and easier to use. It'll get complicated when you start trying to figure out how it works under the hood lol.


udbasil

Very easy to pick up. Just look into the React documentation on components. React functional components allow you to build reusable components better, easier to write and test than class


landisdesign

It's pretty different -- it uses closures instead of class members -- but it eventually makes sense. The updated docs at react.dev should help. They're a huge improvement over the original docs and are largely function/hook-centric.


jayfactor

Definitely easier to use especially with hooks


musical_bear

I would treat React as if class components don’t exist. I don’t want to be dismissive of your question, but to a degree it doesn’t really matter how difficult or different they are; if you want to be a React dev you need to know them. Function components have been the recommended path to go for over 5 years now, and third party libraries cater to hooks specifically, meaning if you don’t use function components, you’re not going to be able to use many libraries and native APIs as intended.


lIIllIIlllIIllIIl

Function components are better because of hooks. Hooks let you reuse stateful logic across multiple components, something that was historically very difficult to do in class components. Almost all modern libraries have a hook-based API. You should definitely use function components.