Using setState in render() causing infinite re-render
Avoiding Infinite Re-renders from setState in render() Calling setState within the render() method (or directly in the function component body) creates an infinite loop because: The Problem Code Correct Solutions….