DEV Community


Discussion on: Do you still use React classes?

bias profile image
Tobias Nickel

I think classes are the second best way to build react apps.

I think react got off from very good track. Initially, it was about render functions. functions that are pure and easy to reason about. there was the formular of data + render = UI.

when react in troduced classes, it is the first vialation of that formular. at least with the classes it is clear where the state is.

today having functional components with react hooks, now the state is somewhere, inside the framework. A pain in the ass for debugging. and reasoning why the ui shows what it shows get harder and harder.

Here I am speaking as a big fan of redux, working hard to have less magic and more clarity in the code.

yes, for statefull components I still prefer classes.

bias profile image
hymanaharon profile image
Aharon Hyman • Edited

I was just about to comment when I saw this. A lot of our app is built with classes and Redux. When working with bigger projects and bigger data calls I find classes handle the state in a way that is cleaner to debug.
I will often have a data layer that is Class and a the children are functional for this reason. But it is really personal preference .
I would also like to add a good developer knows all the tool available to them and is able to chose the correct one for the job, using only functional components and hooks because they are new and cool is not always the best way to go.

ivanjeremic profile image
Ivan Jeremic

Hooks are perfect for state and I know exactly where they are, just because classes are the first thing you learned doesn't mean you have to give up and use still classes, hooks are just so much better and cleaner there is no reason to compare them.

buriti97 profile image

I think typescript works better with hooks than classes too. that's is my opnion:)