3 ms·
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. Y
by franciscop 6y ago
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.
https://reactjs.org/docs/hooks-rules.html https://reactjs.org/docs/hooks-rules.html
- ricardobeat 6y agoThat was close :) See my replies below for a counterpoint.