Skip to content

Commit 058684f

Browse files
committed
add checks for google in load script, add language types to ts
1 parent 0ba11a3 commit 058684f

File tree

6 files changed

+13
-3
lines changed

6 files changed

+13
-3
lines changed

index.d.ts

+1
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ export interface ReactGoogleAutocompleteProps {
99
inputAutocompleteValue?: string;
1010
options?: google.maps.places.AutocompleteOptions;
1111
apiKey?: string;
12+
language?: string;
1213
}
1314

1415
export interface ReactGoogleAutocompleteInputProps

lib/usePlacesWidget.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ function usePlacesWidget(props) {
4545
var event = (0, _react.useRef)(null);
4646
var autocompleteRef = (0, _react.useRef)(null);
4747
var observerHack = (0, _react.useRef)(null);
48-
var languageQueryParam = language ? "&language=".concat(language) : '';
48+
var languageQueryParam = language ? "&language=".concat(language) : "";
4949
var googleMapsScriptUrl = "".concat(googleMapsScriptBaseUrl, "?libraries=places&key=").concat(apiKey).concat(languageQueryParam);
5050
var handleLoadScript = (0, _react.useCallback)(function () {
5151
return (0, _utils.loadGoogleMapScript)(googleMapsScriptBaseUrl, googleMapsScriptUrl);

lib/utils.js

+5
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,11 @@ exports.isBrowser = isBrowser;
99

1010
var loadGoogleMapScript = function loadGoogleMapScript(googleMapsScriptBaseUrl, googleMapsScriptUrl) {
1111
if (!isBrowser) return Promise.resolve();
12+
13+
if (typeof google !== "undefined") {
14+
if (google.maps && google.maps.api) return Promise.resolve();
15+
}
16+
1217
var scriptElements = document.querySelectorAll("script[src*=\"".concat(googleMapsScriptBaseUrl, "\""));
1318

1419
if (scriptElements && scriptElements.length) {

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.3.0",
3+
"version": "2.3.1",
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
@@ -28,7 +28,7 @@ export default function usePlacesWidget(props) {
2828
const event = useRef(null);
2929
const autocompleteRef = useRef(null);
3030
const observerHack = useRef(null);
31-
const languageQueryParam = language ? `&language=${language}` : '';
31+
const languageQueryParam = language ? `&language=${language}` : "";
3232
const googleMapsScriptUrl = `${googleMapsScriptBaseUrl}?libraries=places&key=${apiKey}${languageQueryParam}`;
3333

3434
const handleLoadScript = useCallback(

src/utils.js

+4
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,10 @@ export const loadGoogleMapScript = (
66
) => {
77
if (!isBrowser) return Promise.resolve();
88

9+
if (typeof google !== "undefined") {
10+
if (google.maps && google.maps.api) return Promise.resolve();
11+
}
12+
913
const scriptElements = document.querySelectorAll(
1014
`script[src*="${googleMapsScriptBaseUrl}"`
1115
);

0 commit comments

Comments
 (0)