Skip to content

Commit b375310

Browse files
committed
add check for accessing maps prop of google
1 parent 77561da commit b375310

File tree

3 files changed

+5
-3
lines changed

3 files changed

+5
-3
lines changed

lib/usePlacesWidget.js

+3-1
Original file line numberDiff line numberDiff line change
@@ -73,8 +73,10 @@ function usePlacesWidget(props) {
7373
if (ref && !ref.current) ref.current = inputRef.current;
7474

7575
var handleAutoComplete = function handleAutoComplete() {
76+
var _google$maps;
77+
7678
if (typeof google === "undefined") return console.error("Google has not been found. Make sure your provide apiKey prop.");
77-
if (!google.maps.places) return console.error("Google maps places API must be loaded.");
79+
if (!((_google$maps = google.maps) !== null && _google$maps !== void 0 && _google$maps.places)) return console.error("Google maps places API must be loaded.");
7880
if (!inputRef.current instanceof HTMLInputElement) return console.error("Input ref must be HTMLInputElement.");
7981
autocompleteRef.current = new google.maps.places.Autocomplete(inputRef.current, config);
8082

package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "react-google-autocomplete",
3-
"version": "2.7.1",
3+
"version": "2.7.2",
44
"description": "React component for google autocomplete.",
55
"main": "index.js",
66
"types": "index.d.ts",

src/usePlacesWidget.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ export default function usePlacesWidget(props) {
5959
"Google has not been found. Make sure your provide apiKey prop."
6060
);
6161

62-
if (!google.maps.places)
62+
if (!google.maps?.places)
6363
return console.error("Google maps places API must be loaded.");
6464

6565
if (!inputRef.current instanceof HTMLInputElement)

0 commit comments

Comments
 (0)