useEffect() is an escape hatch for synchronizing with external systems (APIs, DOM manipulation, third-party libraries, browser APIs).
It should not be used for orchestrating the state. React linters will warn against that.
useEffect() documentation | You Might Not Need an Effect
With dependencies - runs after the initial render and when dependencies change: