Skip to content

Commit cab45eb

Browse files
authored
fix(loading): prevent 'undefined' in api url params (#15)
1 parent 636e533 commit cab45eb

File tree

2 files changed

+8
-8
lines changed

2 files changed

+8
-8
lines changed

src/google-map.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,9 +41,9 @@ export default class GoogleMap {
4141
options.googleMapsAPIKey
4242
}&language=${options.language || defaultLanguage}&region=${options.region || defaultRegion}
4343
}${
44-
options.libraries && `&libraries=${options.libraries.join(',')}`
44+
options.libraries ? `&libraries=${options.libraries.join(',')}` : ''
4545
}${
46-
options.mapIds && `&map_ids=${options.mapIds.join(',')}`
46+
options.mapIds ? `&map_ids=${options.mapIds.join(',')}` : ''
4747
}`
4848
);
4949
scriptTag.onload = (): void => {

src/map-provider.tsx

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ export interface GoogleMapProviderProps {
1010
libraries: string[];
1111
language?: string;
1212
region?: string;
13-
mapIds: string[];
13+
mapIds?: string[];
1414
onLoad?: (map: google.maps.Map) => void;
1515
}
1616

@@ -44,7 +44,7 @@ const GoogleMapProvider = (props: GoogleMapProviderProps): JSX.Element => {
4444
const [loading, setLoading] = useState<boolean>(true);
4545
const [map, setMap] = useState<GoogleMap>();
4646

47-
const createGoogleMap = (() => {
47+
const createGoogleMap = () => {
4848
if (!mapContainer) {
4949
return;
5050
}
@@ -67,7 +67,7 @@ const GoogleMapProvider = (props: GoogleMapProviderProps): JSX.Element => {
6767
};
6868
// Create Google Map instance
6969
new GoogleMap(mapOptions);
70-
});
70+
};
7171

7272
// Initializes map on mount
7373
useEffect(() => {
@@ -78,8 +78,8 @@ const GoogleMapProvider = (props: GoogleMapProviderProps): JSX.Element => {
7878
// create new map instance
7979
createGoogleMap();
8080

81-
// Destroy Google Map when component unmounts
82-
return (): void => {
81+
// Destroy Google Map when component unmounts
82+
return (): void => {
8383
map && map.destroyComplete();
8484
};
8585
}, []);
@@ -89,7 +89,7 @@ const GoogleMapProvider = (props: GoogleMapProviderProps): JSX.Element => {
8989
if (!map || !mapContainer) {
9090
return;
9191
}
92-
92+
9393
// Destroy old map instance listeners
9494
map.destroyListeners();
9595

0 commit comments

Comments
 (0)