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.
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.
It's meant for functional components, not classes.
"This" existed in javascript long before classes. No idea why my relevant question is down voted.
"this" isn't bound in functional components because there's nothing to bind it to.
Not in arrow functions, which are very common and any solution should certainly contemplate them.
This doesn't answer the question.
Note they also say:
> We provide a linter plugin to enforce these rules automatically.
Makes me feel a little better.