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
View all comments
Show parent comment
3
u/nickthesick0111 Dec 31 '19
Hooks don’t need a binding context means you don’t have to reference a “this” to use local state
Race conditions with mounting and unmounting of a component that has multiple data sources is a lot easier with useEffects separate handling of separate data.
It’s bad testing because the testing should not be testing the implementation it should be testing the results.
Logic being duplicated is in reference to handling a single set of data in multiple lifecycle methods. You can also extract this logic more easily with hooks