React js 18 should i learn class based components now ?

Recently bought a udemy course and it said we have more functionality when using class based components and when i googled it, it said class based components are no longer useful and it will slowly vanish from react ?

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.

 

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.

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.

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.

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

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

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.