News for hackers. Stuff that matters.
Re:React is becoming a black box by ricardobeat on Thursday September 03, 2020 @09:39AM (#24363913)
Which means you can call it inside a for loop if you have guarantees that the order will always be the same. These are the caveats that don't fit in one paragraph. Also, repeating the rule 'it has to be called in the same order' is not explaining how it works.
Re:React is becoming a black box by cnity on Thursday September 03, 2020 @09:43AM (#24363949)
What makes the fact that each hook call needs to be associated with an index so unacceptable?
Re:React is becoming a black box by ricardobeat on Thursday September 03, 2020 @09:47AM (#24363980)
You could say each call corresponds to a timestamp and they need to be ordered, and the person receiving that information would be none the wiser. It just doesn't lead you to understand what's happening underneath. Some may be fine with stopping at that level of understanding, but the stack-based approach of hooks is quite unnatural for JS and I don't think it is good in the long-term for developers to just 'accept' that as supernatural.
Re:React is becoming a black box by cnity on Thursday September 03, 2020 @09:51AM (#24364013)
So in order to understand not only the basics of the rule, but also the underlying implementation and exactly in what way it would crash, it may require more than a paragraph. I'll concede that. But this is common in programming. As an example, you'd probably spend some time understanding exactly why it is you can't free a pointer twice in C.

There's nothing stopping someone from reading the explanation in the React docs[0] if they want to understand.

[0] https://reactjs.org/docs/hooks-rules.html#explanation