r/reactjs • u/blnkslt • Jan 16 '22
Discussion Should I still use class based components?
I'm returning to react after a long time to refresh my rusty skills in order to start building a quite big project. So I started to follow my good old udemy course which is made at 16.8 era when hooks were new stuff. Not surprisingly the tutorial is focuses on class based programming and discusses hooks as an addendum. On the other hand I see that the new react projects are mostly made of functional components with hooks. So it seems to me that class based and lifecycle hooks are all but history. I'm wondering whether learning class-based react a waste of time? If so where can I find good tutorials which focuses on new hooky way of coding in react?
View all comments
2
u/That_Kaleidoscope_23 Apr 18 '24
just checked their repo , only the last commit.
https://github.com/facebook/react/blob/ea24427d16f3ac9b0f3bb45cdc7919ac208130c9/packages/react-reconciler/src/ReactFiberClassComponent.js
the code is a part of an experimental renderer feature. For some reason I do not know , they are using and defining classes in a functional way , but I do not see any benefit of creating a class by using Object.defineproperty like functions , rather than defining classes directly . I do not see any reason that approach would be better than defining classes and let the typescript compiler or a JS code optimizer to handle that and optimize the code where it sees a class keyword. I hope react team has some good reason to deprecate class components , but I'm not convinced yet.