diff --git a/index.d.ts b/index.d.ts index 835b2da..20ef631 100644 --- a/index.d.ts +++ b/index.d.ts @@ -9,6 +9,7 @@ export interface ReactGoogleAutocompleteProps { inputAutocompleteValue?: string; options?: google.maps.places.AutocompleteOptions; apiKey?: string; + language?: string; } export interface ReactGoogleAutocompleteInputProps diff --git a/lib/usePlacesWidget.js b/lib/usePlacesWidget.js index 5e2ea65..6378bf6 100644 --- a/lib/usePlacesWidget.js +++ b/lib/usePlacesWidget.js @@ -45,7 +45,7 @@ function usePlacesWidget(props) { var event = (0, _react.useRef)(null); var autocompleteRef = (0, _react.useRef)(null); var observerHack = (0, _react.useRef)(null); - var languageQueryParam = language ? "&language=".concat(language) : ''; + var languageQueryParam = language ? "&language=".concat(language) : ""; var googleMapsScriptUrl = "".concat(googleMapsScriptBaseUrl, "?libraries=places&key=").concat(apiKey).concat(languageQueryParam); var handleLoadScript = (0, _react.useCallback)(function () { return (0, _utils.loadGoogleMapScript)(googleMapsScriptBaseUrl, googleMapsScriptUrl); diff --git a/lib/utils.js b/lib/utils.js index d0f518b..947f3ae 100644 --- a/lib/utils.js +++ b/lib/utils.js @@ -9,6 +9,11 @@ exports.isBrowser = isBrowser; var loadGoogleMapScript = function loadGoogleMapScript(googleMapsScriptBaseUrl, googleMapsScriptUrl) { if (!isBrowser) return Promise.resolve(); + + if (typeof google !== "undefined") { + if (google.maps && google.maps.api) return Promise.resolve(); + } + var scriptElements = document.querySelectorAll("script[src*=\"".concat(googleMapsScriptBaseUrl, "\"")); if (scriptElements && scriptElements.length) { diff --git a/package.json b/package.json index 1dde50c..fd760c2 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "react-google-autocomplete", - "version": "2.3.0", + "version": "2.3.1", "description": "React component for google autocomplete.", "main": "index.js", "types": "index.d.ts", diff --git a/src/usePlacesWidget.js b/src/usePlacesWidget.js index 2d84108..64305db 100644 --- a/src/usePlacesWidget.js +++ b/src/usePlacesWidget.js @@ -28,7 +28,7 @@ export default function usePlacesWidget(props) { const event = useRef(null); const autocompleteRef = useRef(null); const observerHack = useRef(null); - const languageQueryParam = language ? `&language=${language}` : ''; + const languageQueryParam = language ? `&language=${language}` : ""; const googleMapsScriptUrl = `${googleMapsScriptBaseUrl}?libraries=places&key=${apiKey}${languageQueryParam}`; const handleLoadScript = useCallback( diff --git a/src/utils.js b/src/utils.js index 130a1fc..da11357 100644 --- a/src/utils.js +++ b/src/utils.js @@ -6,6 +6,10 @@ export const loadGoogleMapScript = ( ) => { if (!isBrowser) return Promise.resolve(); + if (typeof google !== "undefined") { + if (google.maps && google.maps.api) return Promise.resolve(); + } + const scriptElements = document.querySelectorAll( `script[src*="${googleMapsScriptBaseUrl}"` );