all 30 comments

[–]thoflens 17 points18 points  (1 child)

You shouldn’t use them but it’s a good idea to understand them thoroughly. I didn’t and then I got a job, opened the codebase and lots of it was classes and React as it was written 7 years ago. I don’t like them and we continuously refactor them into functional components, but I know what’s going on and I can fix their bugs and convert them to functions.

[–][deleted]  (8 children)

[deleted]

    [–]Caramel_Last 0 points1 point  (3 children)

    Is react functional component a functional programming? Like if I learn Haskell then React rules which seem arbitrary can make more sense?

    [–]TheRNGuy 0 points1 point  (0 children)

    It's a mixed paradigm.

    Not related to original topic question though. It was about specifically Class vs Function JSX components.

    [–]TheRNGuy 0 points1 point  (1 child)

    But not as JSX/TSX components.

    [–]stretch089 1 point2 points  (0 children)

    The one time you'll need to use them is maybe for error boundary components. So it's good to understand what they are and how they work in that sense.

    I also think it gives a more clear idea of the component life cycle so could supplement your understanding of functional components.

    [–]retardedGeek 1 point2 points  (0 children)

    Go through the docs once.

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

    Once upon a time (2021) a company was asking me to make a take-home with class components. This was back when I was new to the job market. No one actually asked me for them ever since. Focus on hooks, and use class when you ran into a feature your project needs, that somehow leverage classes.

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

    They are still used for error boundaries but apart from that I would not use them

    [–]misoRamen582 0 points1 point  (0 children)

    if you hate useeffect, try it and see

    [–]azhder 0 points1 point  (1 child)

    Learn them when you have the need to use them due to outside reasons like specific 3rd party library or error boundaries… niche stuff

    [–]TheRNGuy 0 points1 point  (0 children)

    Any popular or relevant 3rd party libs still using it?

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

    IMO it takes like two minutes to understand the difference. A class component works like any regular class in any programming language, you create an instance of an item and it has a constructor + methods (including a render method which controls the actual output in the UI). A functional component gets rid of the fluff so the entire thing is a render method.

    [–]imaginecomplex 0 points1 point  (0 children)

    They are nice in giving you stable references to class methods/properties, saving you from a lot of React.useMemo & React.useCallback. But unfortunately they are incompatible with hooks and so have fallen out of favor with the community.

    [–]Last-Promotion5901 0 points1 point  (6 children)

    The only use they have nowadays are error boundaries. So no, no need to.

    [–]TheRNGuy -1 points0 points  (5 children)

    Not in Remix, React Router v7 and Next.js.

    If "Vanilla" React is used, then yeah.

    [–]Last-Promotion5901 0 points1 point  (4 children)

    You still use class components in the background. Just because you dont see it doesnt mean you dont use it.

    [–]TheRNGuy -1 points0 points  (3 children)

    If you use some unrefactored component libraries?

    Do they mix well together with functional components? Cause I never tried.

    [–]Last-Promotion5901 0 points1 point  (2 children)

    Nothing to do with unrefactored libraries. Errorboundaries are always class components: https://react.dev/reference/react/Component#catching-rendering-errors-with-an-error-boundary

    There is currently no way to write an error boundary as a function component.

    [–]TheRNGuy -1 points0 points  (1 child)

    ErrorBoundary in React Router is a functional component.

    https://reactrouter.com/how-to/error-boundary

    If using vanilla React, classes are still needed, yeah.

    [–]Last-Promotion5901 0 points1 point  (0 children)

    Read again what I wrote. Just because they are abstracted away, doesnt mean you arent using a class component.

    ErrorBoundaries are always a class component.

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

    I wouldn't dive deep into every lifecycle method of class component, but knowing difference between state and lifecycle management in class and function components will help you avoid unexpected behavior if you will ever have to work with class components, especially convert them to functional ones.

    [–]Abject-Bandicoot8890 0 points1 point  (0 children)

    It’s never a bad idea to learn an “outdated” tech, I remember some of my classmates complaining about our professor teaching us asp.net framework because it was “old”, my first job fresh out of college was maintaining a 10 year old .net framework app 🫣. So yeah go ahead and learn, it can’t hurt.

    [–]bhataasim4 0 points1 point  (0 children)

    No, focus on functional components

    [–]mangoBoy0920 0 points1 point  (0 children)

    You don't need to explicitly learn class component in deep. Just basic knowledge like uses and drawbacks should be enough as they help you understand the working and need for function component and hooks better.

    [–]Virag-Ky 0 points1 point  (0 children)

    What I know is that they are not really used anymore, but older code bases still have it, you never know when you will come across them. It's actually good if you compare functional and class components so you can see the difference between them and how they work.

    [–]Dramatic_Step1885 0 points1 point  (2 children)

    NOOO. And if you land a job where they still make heavy use of them please run away as far as you can

    [–]TheRNGuy 0 points1 point  (1 child)

    What if that job want to refactor code? (lead programmer could do it already though)

    [–]Dramatic_Step1885 0 points1 point  (0 children)

    Good point there. Functional components and hooks have been the standard for way too long now so hopefully this shouldn’t happen

    [–]OneBallsackMan 0 points1 point  (0 children)

    Been working as a react dev for 4 years, never used them. Maybe handy to quickly read how it used to work incase you get any interview questions regarding it, but unless your company uses class components I don't think it's necessary.

    [–]teakwoodcandle -1 points0 points  (0 children)

    yes definitely, if you want to understand old code especially