As of React 16 it’s not recommended to use classes for react components due to the following 3 pain points:
- Reusing logic between multiple components leads to deeply nested components that are not readable and error prone
- Mixed in logic in the lifecycle methods often cause unnecessary and unwanted side effects
- Hooks usually reduce bundle size
src: reactjs - React.js state object vs useState hook? - Stack Overflow
So I guess my question is:
With so many errors/open forums on the jamming project and the teaching differing from industry standards as described above, why do we focus so heavily on class components instead of quick section laying out class syntax in case we see it in the wild? Is there an advantage to having a deeper understanding of class syntax?
My understanding is that the class component course was written back when class components were still the norm, and they are still useful to know as even though functional components are recommended going forward, you may still end up working on legacy React projects which are written in class-based terminology and would be a truck-load of work to refactor due to the sheer size.
However, if instead of doing one of the Skill Paths you instead do the Learn React course, you do actually learn about functional components in the Hooks section and onwards. The courses may end up being updated as React continues to develop and functional components become the most commonplace thing, but whilst in this transitional period it’s still important to know both. After all Hooks were only introduced in version 16.8, that means there were so many more versions of React before Hooks until where we are today in React 18.
Besides in my personal opinion, functional components weren’t too hard to learn once you knew class components well. It takes adjusting to learn the Hooks and the new way of using states without
this, however if you know the basics of components it’s relatively easy to jump into functional after that.
Thank you for the reply!
I’m in the full stack career path which does cover hooks after class components, albeit more briefly.
My confusion was if hooks are the recommended practice why we wouldn’t focus more on those and touch on class components the way we do hooks.
However, that’s just an opinion and I hear you on a lot of projects being written prior to Feb 2019 when React 16.8 was released.
Have a great day.
I like Codecademy and think it’s one of the best resources for coding. That being said, it doesn’t feel great to have to pay for outdated knowledge. The fact that some of the course content hasn’t been updated in years is just outright lazy.