Skip to content

Commit

Permalink
Wrap all window references in type check for SSR useage
Browse files Browse the repository at this point in the history
  • Loading branch information
ryanhefner committed Aug 25, 2019
1 parent 2094711 commit 059dfb7
Showing 1 changed file with 11 additions and 7 deletions.
18 changes: 11 additions & 7 deletions src/GoogleMap.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,16 +36,18 @@ const CALLBACK_MAP = {
'zoom_changed': 'onZoomChange',
};

window['reactMapsGoogleInstances'] = [];
window['reactMapsGoogleInit'] = () => {
window['reactMapsGoogleInstances'].forEach(instance => instance());
};
if (typeof window !== 'undefined') {
window['reactMapsGoogleInstances'] = [];
window['reactMapsGoogleInit'] = () => {
window['reactMapsGoogleInstances'].forEach(instance => instance());
};
}

class GoogleMap extends Component {
constructor(props) {
super(props);

const scriptLoaded = window.google && window.google.maps && window.google.maps.Map
const scriptLoaded = typeof window !== 'undefined' && window.google && window.google.maps && window.google.maps.Map
? true
: false;

Expand All @@ -56,11 +58,13 @@ class GoogleMap extends Component {

this.onScriptLoad = this.onScriptLoad.bind(this);
this.onScriptInit = this.onScriptInit.bind(this);

window['reactMapsGoogleInstances'].push(this.onScriptInit);
}

componentDidMount() {
if (typeof window !== 'undefined') {
window['reactMapsGoogleInstances'].push(this.onScriptInit);
}

this.renderMap();
}

Expand Down

0 comments on commit 059dfb7

Please sign in to comment.