Re:React is becoming a black box
by franciscop on Thursday September 03, 2020 @09:37AM
(#24363893)
Because React keeps track of the hooks you are using by the call order, and a loop might indicate than in different rerenders it might have different lengths. You actually can do it, it's just the linter trying to avoid you shooting yourself in the foot.
In fact the linter explains exactly that in a paragraph:
> React Hook "useState" may be executed more than once. Possibly because it is called in a loop. React Hooks must be called in the exact same order in every component render.
In fact the linter explains exactly that in a paragraph:
> React Hook "useState" may be executed more than once. Possibly because it is called in a loop. React Hooks must be called in the exact same order in every component render.
https://reactjs.org/docs/hooks-rules.html