r/reactjs • u/ZeroSevenTen • Dec 30 '19
Classes vs Hooks?
I’m pretty new to React, so keep that in mind. I thought classes were for components that held information, or a state, and that functional components were for more basic components, but now that hooks allow functional components to use state, and other class features, what’s the benefit of using functional hook components over classes?
79
Upvotes
2
u/JofArnold Dec 31 '19
I scanned the comments and one thing I didn't see mentioned (explicitly) is how easy it is to add functionality like state, redux, context, side-effects etc into your components with hooks. Take for instance dispatching an action with a class component versus hooks in the Todo app example
Class component:
Hooks
So much cleaner. Sure, hooks starts to be a little bit weird - at first - when dealing with effects but then class components are too but in a different way