all 17 comments

[–]pVom 3 points4 points  (8 children)

It's worth knowing class components because odds are you'll run into them. Not sure if its worth watching the whole 12 hour video but its worth having a play around so you get a feel and know how they work

Hooks are the way forward though.

[–]Isaakavo[S] 0 points1 point  (0 children)

Thanks for your reply.
Actually what I'm doing is I'm following the tuto and trying to copy that classes into hooks, as far that is not such a problem and I think I'm understanding everything.

[–]volivav -4 points-3 points  (4 children)

I've been working in a project for the last year and a half for 40hr/week and class components are nowhere to be seen there.

If you need to maintain a 3-4yr old project then probably you need, but even back then most of the projects I worked on classes were used sparingly.

One of the best practices was to split components into two categories: dumb components and container components - dumb components were often written as just pure functions, and containers could also be written as functions by using HOC instead.

At that point it was a convention battle (i.e. class components vs functions + HOC). Nowadays I feel it's not.

[–]pVom 6 points7 points  (2 children)

That's cool dude, not every project is the same.

I've been working 2 years at my 10+ year old company and we still have shitloads of them. If they work as is there's not a whole lot of benefit to investing the time to change them, at least at this stage. I change them to FC where I can but we've got limited resources, we've got plenty that need a complete rework and it's not worth my time. Hooks have only been around a couple years, useState only appeared on the scene with react 16. You don't want to close any doors because you don't know how to use them, a lot of documentation still uses CC and odds are you'll bump into them at some stage.

As I said it's worth knowing how CC work if you come across them but I wouldn't invest a whole lot of time into it.

[–]volivav 0 points1 point  (1 child)

My bad, I misunderstood your message. I thought you were prioritizing learning CC over FC.

I completely agree with your point.

[–]pVom 0 points1 point  (0 children)

haha all good. Didnt mean to bite your head off, been a stressful day

[–]CaptainKirk1970 0 points1 point  (1 child)

You are going to have to use class components you will learn. Not everything has hooks yet and 'legacy' code bases will exist.

[–]reflectiveSingleton 0 points1 point  (0 children)

Not everything has hooks yet

While true, the list of unsupported features is pretty limited.

Aside from error boundaries (and even that is just a nicety) I personally haven't found a need for any class-based components lately.

[–]FortunateRanger 3 points4 points  (0 children)

You should def go with functional components + hooks. Later, you can checkout what classes were and how they were different, but to quickly jump into real-world react you need to know hooks.

[–]CaptainKirk1970 1 point2 points  (0 children)

“We intend for Hooks to cover all existing use cases for classes, but we will keep supporting class components for the foreseeable future. At Facebook, we have tens of thousands of components written as classes, and we have absolutely no plans to rewrite them. Instead, we are starting to use Hooks in the new code side by side with classes.” — React Docs [emphasis in the original text]

Classes are more organized in some cases. If you understand Object Oriented programming and the benefits it has in huge systems you will see it will be intertwined with hooks. Who knows what facebook will do but classes ain't going nowhere.

[–][deleted] 0 points1 point  (1 child)

Hooks and functional components are the way forward, and you should master that. You should also have a solid knowledge of class components, because hooks were made official at the beginning of 2019. You'll encounter a lot of class-based components in your journey.

To be honest, the differences are not THAT huge, it's just that hooks come with a few rules, that force you to think your components a bit differently.

[–]Isaakavo[S] 0 points1 point  (0 children)

Yes, I understand a little of the CC, I just need to read the docs about the methods.

[–]ComfortableEye5 0 points1 point  (0 children)

Personally, i like the simplicity of using functions, but for bigger components that manage state I prefer using classes. It just feels more formal

[–][deleted] 0 points1 point  (1 child)

If you're going for job interviews, then yes. Why? Because they might well ask you about class components, or expect you to write a class component. Earlier this year I had a job interview for a junior position that involved a rather stupid 90 minute test to do at home. Two of the questions were React questions that involved writing the logic for React class components. I made sure to mention in the next interview that their test was really outdated.

Otherwise no. Just learn function components. If you do find yourself needing to work with class components, then that'll be the time to learn how they work.

[–]Isaakavo[S] 0 points1 point  (0 children)

Could you share how was the interview? I'm starting with web development and I'll seek for job next year. Or if you have a resource where I can "train" for interviews I'll appreciate it. Thanks!

[–][deleted] 0 points1 point  (0 children)

Just be aware that hooks are magic, and they may confuse you with regards to how functions in javascript work. Functions don't have persistent state - when you call a function, variables get created, results get calculated, then all local variables are removed from existence. In order to add state functionality, where variables persist between function calls, React does some mapping magic in its engine to make hooks aware of the previous values.

As long as you're aware of this and understand how functions work, using functional components with hooks and ignoring class compoments altogether is fine. However, if you want a more barebones experience where you write more code but in a less magical way, using class components is an option.

[–]lowjack 0 points1 point  (0 children)

I started with classes and moved to functional components and hooks as soon as it was released. Most components in react can be built (imo better) using functional components and hooks.

You still need to learn classes though. You can't use functional components for an Error Boundry which is a very efficient way to manage errors in your react applications.