Anonymous login without button click

The tutorials I find such as this one trigger app.logIn(Realm.Credentials.anonymous()) from a button click.

I would like to call app.logIn(Realm.Credentials.anonymous()) at the beginning of a React application so that new users don’t need to press a button, but I am worried this will overwrite cookies set by other providers.

I notice that there is a app.currentUser property, but I am not sure if it is safe to check if(currentUser == null) loginAnonymous() right away or if I need to wait for an http request to finish.