Setting state inside render() leading to infinite loop
Avoiding Infinite Loops from State Updates in Render A critical React mistake is calling state update functions (like setState or state setters from useState) inside the render() method or function….