How to fix Warning: Cannot update a component from inside the function body of a different component in React | DevErrors