Specifically, it runs at the end of a commit after the screen updates, after every render
In React, rendering should be a pure calculation of JSX and should not contain side effects like modifying the DOM.
Don't useState as it will trigger a new render, that will trigger useEffect again
You can tell React:
Typically, if you get this message, you need to encapsulate your state in a useEffect function
Warning: Cannot update a component (`xxxxx`) while rendering a different component (`xxxxxx`).
To locate the bad setState() call inside `xxxx`, follow the stack trace as described in https://reactjs.org/link/setstate-in-render