Home:ALL Converter>The order of react hooks

The order of react hooks

Ask Time:2020-09-01T06:31:35         Author:Nikita Vlasenko

Json Formatter

I am trying to understand how React hooks work reading official docs:

https://reactjs.org/docs/hooks-rules.html

And there they say that react relies on the order hooks are called. I still don't get why the order is of importance and why a hook placed in a conditional will cause bugs, could anyone explain?

Particularly this sentence makes me confused:

React wouldn’t know what to return for the second useState Hook call

why?? Does react somehow binds useState with useEffect?

Then, this question:

So how does React know which state corresponds to which useState call?

From my understanding there is only one state, so why they are talking about states (plural)?

Author:Nikita Vlasenko,eproduced under the CC 4.0 BY-SA copyright license with a link to the original source and this disclaimer.
Link to original article:https://stackoverflow.com/questions/63678998/the-order-of-react-hooks
yy