News for hackers. Stuff that matters.
Re:Introducing Hooks by kiliancs on Thursday October 25, 2018 @02:14PM (#18303137)
> React assumes that if you call useState many times, you do it in the same order during every render.

Note they also say:

> We provide a linter plugin to enforce these rules automatically.

Makes me feel a little better.

Re:Introducing Hooks by adriancooney on Thursday October 25, 2018 @04:37PM (#18304378)
I doubt the linter will enforce the same-ordering, that would require state between runs. I think the linter just ensures hooks are run at the top level in the functional component.
Re:Introducing Hooks by atomwaffel on Friday October 26, 2018 @04:34PM (#18312517)
And it wouldn't need to. You're free to move around calls to useState() to your heart's content in your code, you just need to call them in the same order during the lifecycle of your component.
Re:Introducing Hooks by maaaats on Thursday October 25, 2018 @03:29PM (#18303836)
Why couldn't one just pass in `this` to useState, a key, or something similar?

Like, if I have two state variables, pass in a name for both, instead of relying on the order being the same.

Re:Introducing Hooks by needz on Thursday October 25, 2018 @03:45PM (#18303964)
It's meant for functional components, not classes.
Re:Introducing Hooks by maaaats on Thursday October 25, 2018 @04:39PM (#18304388)
"This" existed in javascript long before classes. No idea why my relevant question is down voted.
Re:Introducing Hooks by kaoD on Thursday October 25, 2018 @06:08PM (#18305014)
"this" isn't bound in functional components because there's nothing to bind it to.
Re:Introducing Hooks by kiliancs on Thursday October 25, 2018 @05:10PM (#18304617)
Not in arrow functions, which are very common and any solution should certainly contemplate them.
Re:Introducing Hooks by Touche on Thursday October 25, 2018 @04:09PM (#18304160)
This doesn't answer the question.
Re:Introducing Hooks by zwily on Thursday October 25, 2018 @05:04PM (#18304578)
And what would `this` be in that function?