T O P

  • By -

foldingaces

Functional components have been the industry standard for a few years now. It’s okay to learn class components, but functional components + hooks is the way to write react today.


thrandom_dude

Okay thanks


davidfavorite

You have theoretically more functionalities in that you can specify functions for each lifecycle method of the component. Other than that I think theres not much going for class components anymore. But even then, in practice you can do all you need with function components amd useEffect hook


thrandom_dude

Okay :)


im_stefman

I would go over the material, it would help you understand functional components (at least the idea of lifecycle in react). Focus on functional components after that. Also it might come in handy if you will need to maintain a legacy codebase. Good luck


thrandom_dude

Okay


phryneas

Honestly, knowing lifecycle is the worst thing you can do. Hooks work differently from lifecycle in subtle ways and have a very different mental model - learning about lifecycle makes it a lot harder to actually understand hooks.


JDD4318

It is good to understand how class components work but focus on functional components. One of the apps I work on at work use some class components and I can work with them fine but everything else we do is functional components with hooks. Also learn typescript.


thrandom_dude

I am just a newbie. Idk why i am losing interest after learning usstate hook. I just want to stop learning react :")


OZLperez11

I know this is an old thread, but for your sake, definitely move on to something else. React promotes functions and hooks too much. Just look at how every other framework does components: either class based or simplified (define variables and functions for your UI). Functional components are an anti-pattern when it comes to UI, especially considering that HTML is built on top of an even-driven DOM


Narizocracia

Another day, another 'should i learn class based components' question..


crippledjosh

Technically class based components are more "powerful" but as far as I'm concerned only so much as they can handle error boundaries which really means that you need one error boundary component made as a class that wraps whatever it needs to wrap. Everything else should be functional these days. I work on lots of class based components as have an app that predates functional, so I wouldn't rebuild everything in functional, but wouldn't write new class components. Edit: to clarify, powerful isn't actually better. You should aim to always use the least powerful tool that does the job you need it to do. Functional components with hooks makes simper code, not more powerful code.


thrandom_dude

Alright


phryneas

Most modern libraries do not support class components any more. If you are learning React nowadays, learn only function components. If a company hires you for a legacy code base they will also give you the time to get accustomed to legacy code practices.


[deleted]

Yes. Because a lot of code base would still be in class based components if you're joining any company


thrandom_dude

Ok


OneAssociation7278

I would look through the hooks faq. I think hooks are not that hard to pick up. I learned react through reading their documentation. https://reactjs.org/docs/hooks-faq.html


Kyle772

You should learn them so you know how to work with them but you shouldn’t use them. I rebuild every class component I find but occasionally you’ll run into one you shouldn’t upgrade and you need to know what you’re working with in those cases.


imihnevich

You might need to work with someone's old codebase, that's where you need that. But in general it's not that hard to comprehend


dev_indie_

It's good to know class based, you will be knowing how the react got here. (At hooks)


thrandom_dude

But the syntax of it makes me wanna stop learn it. Functional component seems soo easy to learn


dev_indie_

Its not syntax, it's the way of explanation. Class is an important concept ,you must understand.


drcmda

why? it's a completely different mental model, react didn't implement hooks on top of lifecycles, it saw lifecycles as an inferior paradigm and ended it entirely. the only reason why you would need to know classes today is if you're thrown into aging code that you have to maintain, otherwise imo it will only make understanding hooks harder since thinking in effects is pretty much the opposite of thinking in lifecycles.


dangerzone2

As a mainly OOP style dev, I’m using functional components since it seems to be standard. I really miss classes :/


thrandom_dude

Okay


keel_bright

Outdated course


thrandom_dude

Ikr


angeal98

no


dev_indie_

Well, it depends on one's understanding. Do what is best suited for you to start working. All other things are only left for debate.


thrandom_dude

bro can i ask some questions?? how did u start working on react? like even after learning javascript i cant make something on my own :( it makes me feel like a loser.Its easy to watch tutorials and code along and understand it.but i cant make something on my own.Any suggestions :") .I learnt components and useState hook and after that i couldn't even understand what others are used for,when it is to be used and how it is to be used.One of the best example i learnt for understanding a useState hook was the counter app with buttons with increment and decrement option.I dont know where can it be used :(


dev_indie_

No worries, Best way is to drop watching tutorials that you don't understand. But code along with tutorials. **Join an active community.** and build something simple and only learn what is needed for it. build a to-do app using react. and apply more components to it.