Back in February 2019, React 16.8. introduced Hooks, a new way of using state and other React features without writing a class.
As of November 2020, the class syntax is still supported, and React official documentation states there are no plans to remove classes from React.
Do you still maintain some code where you have to use React classes? What about the projects you create from the ground-up?
Oldest comments (26)
I'm still a newbie and only used classes a few times while I didn't knew how to use
useEffect()
π€¦
Personally no but I still see them in lot of codebases, feels nostalgic haha
No thanks god!
At least for ErrorBoundary. For Containers, they are worth considering. But for everything else, there's function components.
I'm using class component only on old components - existing components. Creating new components always I write components using Hooks API, because it's clearer and easy to use. There are quite benefits over the Hooks API which can show when put it on practice.
yes sometimes...
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.
guess he is suppirting my point.
dev.to/hymanaharon/why-i-will-no-l...
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.
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.
I think typescript works better with hooks than classes too. that's is my opnion:)
I'm using mix of both. All my child components are Functional components with hooks and Container components where I need some more states to be managed and need to use some lifecycle methods extensively then only I use Class component if not then Functional component with hooks there too.
I use Hooks everywhere.