How do I use the window object in ReactJS?
Component methods are not attached to the window
object. MyApp.handleGoogleClientLoad
is not going to be aliased to window.handleGoogleClientLoad
which is what the google API script is likely trying to invoke.
If you want the Google API to call a method on your component you're going to have some trouble as there's no guarantee that your component will be mounted before or after your Google API script loads. If you want to guarantee that you'd have to inject the script after the component mounted and register the function in the componentDidMount
method. You can use something like loadjs
componentDidMount() {
window.handleGoogleClientLoad = function() {
// log to console
}
loadjs('https://apis.google.com/js/client.js?onload=handleGoogleClientLoad')
}