0

I have an application in ReactJs where I am trying to navigate to the dashboard after successfully authenticating. Still, I don't understand why it doesn't advance to the next page only after reloading the page.

I reproduced my code in a sandbox for a better understanding.

https://codesandbox.io/s/holy-snow-j2etkj?file=/src/App.js

enter image description here

Omairys
  • 69
  • 1
  • 6
  • 1
    As per your codesandbox, it is working perfectly fine. I don't understand what's the issue here ? – Pratik Wadekar Jul 27 '22 at 13:11
  • Well, in this console it doesn't show, but in the browser, I get a horrible error and sometimes it crashes. (I updated the image in the question) – Omairys Jul 27 '22 at 13:51

1 Answers1

0

There was a similar error received in this stack overflow question --> Cannot update a component while rendering a different component warning

So the answer was that you were setting the state in a component which was rendering multiple times. So the setstate was called multiple times.

The setstate had to be wrapper in a useEffect hook to fix the error so that it is called only once.