Skip to content

Commit 059dfb7

Browse files
committed
Wrap all window references in type check for SSR useage
1 parent 2094711 commit 059dfb7

File tree

1 file changed

+11
-7
lines changed

1 file changed

+11
-7
lines changed

src/GoogleMap.js

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -36,16 +36,18 @@ const CALLBACK_MAP = {
3636
'zoom_changed': 'onZoomChange',
3737
};
3838

39-
window['reactMapsGoogleInstances'] = [];
40-
window['reactMapsGoogleInit'] = () => {
41-
window['reactMapsGoogleInstances'].forEach(instance => instance());
42-
};
39+
if (typeof window !== 'undefined') {
40+
window['reactMapsGoogleInstances'] = [];
41+
window['reactMapsGoogleInit'] = () => {
42+
window['reactMapsGoogleInstances'].forEach(instance => instance());
43+
};
44+
}
4345

4446
class GoogleMap extends Component {
4547
constructor(props) {
4648
super(props);
4749

48-
const scriptLoaded = window.google && window.google.maps && window.google.maps.Map
50+
const scriptLoaded = typeof window !== 'undefined' && window.google && window.google.maps && window.google.maps.Map
4951
? true
5052
: false;
5153

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

5759
this.onScriptLoad = this.onScriptLoad.bind(this);
5860
this.onScriptInit = this.onScriptInit.bind(this);
59-
60-
window['reactMapsGoogleInstances'].push(this.onScriptInit);
6161
}
6262

6363
componentDidMount() {
64+
if (typeof window !== 'undefined') {
65+
window['reactMapsGoogleInstances'].push(this.onScriptInit);
66+
}
67+
6468
this.renderMap();
6569
}
6670

0 commit comments

Comments
 (0)