Skip to content

Commit a88431d

Browse files
authored
Merge pull request #121 from ubilabs/fix/google-maps-error
fix(google-maps-provider): quick fix google maps check
2 parents a3d3ba4 + e885ef5 commit a88431d

File tree

3 files changed

+1043
-94
lines changed

3 files changed

+1043
-94
lines changed

library/src/google-maps-provider.tsx

Lines changed: 16 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,7 @@ export const GoogleMapsProvider: React.FunctionComponent<
6969

7070
const defaultLanguage = navigator.language.slice(0, 2);
7171
const defaultRegion = navigator.language.slice(3, 5);
72+
7273
/* eslint-disable camelcase */
7374
const params = new URLSearchParams({
7475
key: googleMapsAPIKey,
@@ -150,19 +151,24 @@ export const GoogleMapsProvider: React.FunctionComponent<
150151

151152
// Handle Google Maps map instance
152153
useEffect(() => {
153-
let newMap: google.maps.Map | undefined;
154+
// Check for google.maps is needed because of Hot Module Replacement
155+
if (
156+
isLoadingAPI ||
157+
!mapContainer ||
158+
!(typeof google === 'object' && typeof google.maps === 'object')
159+
) {
160+
return () => {};
161+
}
154162

155-
if (!isLoadingAPI && mapContainer) {
156-
newMap = new google.maps.Map(mapContainer, mapOptions);
163+
const newMap = new google.maps.Map(mapContainer, mapOptions);
157164

158-
google.maps.event.addListenerOnce(newMap, 'idle', () => {
159-
if (onLoadMap && newMap) {
160-
onLoadMap(newMap);
161-
}
162-
});
165+
google.maps.event.addListenerOnce(newMap, 'idle', () => {
166+
if (onLoadMap && newMap) {
167+
onLoadMap(newMap);
168+
}
169+
});
163170

164-
setMap(newMap);
165-
}
171+
setMap(newMap);
166172

167173
// Remove all map related event listeners
168174
return () => {

0 commit comments

Comments
 (0)