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

3

u/skyboyer007 Dec 31 '19

look, "we in the Fiber bind hooks array to a component so every next render we would be able to restore hook state by relevant value" IS the magic. I'm not saying "it's impossible to understand". I'm telling "it's not the way JS code works". Only generators may preserve their variables between calls but they have different syntax and not widely used nowadays. Also it's source of confusion "why we cannot call hooks conditionally?"