News for hackers. Stuff that matters.
Re:Crank.js – Write JSX-driven components with functions, pr... by flowerlad on Saturday April 18, 2020 @06:35AM (#22906758)
> hooks use closures for state and if you call hooks in wrong order you get the wrong values back.

Calling hooks in wrong order gets the wrong value back? Can you explain this one?

Re:Crank.js – Write JSX-driven components with functions, pr... by rossta on Saturday April 18, 2020 @07:17AM (#22906925)
Hooks rely on a persistent call index. Here are a few posts that explain in more detail:

https://overreacted.io/why-do-hooks-rely-on-call-order/

https://github.com/reactjs/rfcs/pull/68#issuecomment-4393148...

Re:Crank.js – Write JSX-driven components with functions, pr... by TomMarius on Saturday April 18, 2020 @02:02PM (#22909659)
But why would you even change the order? I don't understand how can this be an issue if you treat it as a static declaration which it simulates.
Re:Crank.js – Write JSX-driven components with functions, pr... by rssbnjmnfrncs on Sunday April 19, 2020 @04:53AM (#22914491)
What if you wanted to return early in the component? E.g. a hook has returned a certain value and you now want to stop all other execution and return null. With hooks you can't as that would change the order.
Re:Crank.js – Write JSX-driven components with functions, pr... by TomMarius on Sunday April 19, 2020 @08:30AM (#22915454)
Yeah but you also wouldn't try to return in the middle of function argument declarations. I know it's a little weird, but just treat it as a declaration block and you won't have any problems, what you're proposing is impossible with react architecture as a whole anyways (because the next component would get wrong state cells, it's a stack).