My index.html
My suggestions:
Change your google API script tag to be this, where you remove async
and defer
Get rid of your start function, which will now run the console.log
fine and dandy, but the second bit of code will cause the same issue as it will also be running asynchronously.
Modify your react code, so that the componentWillMount
calls the contents of that function instead:
componentWillMount() {
gapi.load('auth2', () => {
auth2 = gapi.auth2.init({
client_id: 'urhaxorid.apps.googleusercontent.com',
scope: 'profile email',
onLoad: () => {
this.setState({ mapLoaded: true });
}
});
});
}
componentDidMount() {
if (this.state.mapLoaded) {
console.log(gapi.auth2.getAuthInstance());
}
}
Please bear in mind that I don't know what the onLoad
is for google apis, and I am not 100% sure how to best do the setState
stuff, but it may be a starting block.