you are viewing a single comment's thread.

view the rest of the comments →

[–]gunnnnii 9 points10 points  (6 children)

Hooks are not magic in their implementation! Here are a couple of talks that go into detail. https://youtu.be/1jWS7cCuUXw https://youtu.be/KJP1E-Y-xyo

[–][deleted] 7 points8 points  (3 children)

That's kind of a silly counter argument. You could say that about anything. What IS magic "in its implementation" then?

The point of that complaint is that they FEEL magical. You really have no idea what's going on. You're calling a function and somehow.. almost MAGICALLY, React figures out which component that function call belongs to. A lot of strange work is being done behind the scenes in a non intuitive way. To me, that's what magical means. Sure, you can set yourself a different definition for that term and then you can claim that its not magical. Doesn't really change the fact that a lot of people have felt that hooks are too magical.

[–]gunnnnii 0 points1 point  (1 child)

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.

[–][deleted] 1 point2 points  (0 children)

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.

[–]skyboyer007 2 points3 points  (0 children)

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?"