React funcional vs class component

Im a bit confused about this.

As far i know
In February 16, 2019 React 16.8 version was released. Now hooks allows you to use state in functional components. Also lifecycle methods etc.

Still, i find lots of articles, after this release, saying “functional component is dumb” and “always use class if you have state”.
Even FCC:

An other article says functional components are even better now:

If you can do both, which one is better to use?
If its personal preferance, which one do you prefer, and why?

My personal preference: hooks by default, classes for specific cases (e.g. decorators).

Such is the life of a JS developer. The landscape changes very fast and the new best thing always seems to come around every few months. Legacy React code using classes is going to be around for a while and all the cool developers want to use hooks now, so you should become familiar with both if you want to work with React code. As to which is best? Heck if I know but most likely a few years down the road the React team will come out with something even better than the both of them :slight_smile:


HI @sconty!

I am currently working through the fourth react project in FCC and used class based components and stateless functional components for the last three projects.

I am now learning about hooks.

The thing to realize is that EVERYONE HAS AN OPINION.

This doesn’t make it fact.

I have read tons of articles that all seem to contradict each other which made me realize that everyone has an opinion.

At this stage of learning, I would just learn what is possible with react and the different ways of doing things.

I wouldn’t stress out about what is the cool way. Just try your best to learn what is possible with libraries and frameworks. But as mentioned before, technology and always changing. So in a few years alot of things you are doing now will be out of date and you will have to learn something new.

Also, for the FCC articles, those were written by a community of volunteers all around the world with varying levels of programming experience.
So they are not necessarily the official voice of FCC but rather just providing their own take on different aspects of programming.

1 Like

This topic was automatically closed 182 days after the last reply. New replies are no longer allowed.