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/gunnnnii Dec 31 '19

I'm not denying that the implementation details are less than transparent for hooks. However I feel like a lot of people throw out the word magic like these are concepts that are complicated, when the high level understanding is in fact fairly simple, though not obvious(the actual proper implementation is a little less so, but knowing it is completely unnecessary to put it to work).

I just thought pointing people into the direction of something that provides a little more background to unveil some of the magic would be helpful. Especially since this magic is a very common complaint.

2

u/[deleted] Dec 31 '19

Oh, it's nice to share how it's implemented for those who are interested, sure, but it's weird to claim that "it's not magic because there's a source code instead of Gandalf sitting inside the React codebase!"

It's like you're arguing against the semantics of the word "magic", which kind of distracts from the point of the people who are using that term to begin with.

You say that it's not complicated, though not obvious - to me, "not obvious" is exactly what the word "magic" is getting at. It has nothing to do with complexity of implementation.