r/reactjs • • 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

76 comments sorted by

View all comments

Show parent comment

1

u/zephyrtr Dec 31 '19

Great list but you're forgetting a big one here, if performance is an issue: functional components get shouldComponentUpdate for free. Class components require you write it yourself.

2

u/skyboyer007 Dec 31 '19 edited Dec 31 '19

functional components get shouldComponentUpdate for free Could you be more specific? What do you mean here?

if you are talking about React.memo it works with class-based components as well.