Skip to content

Commit db92f38

Browse files
committed
Use default value for libraries, add string type to libraries type
1 parent 00ae294 commit db92f38

5 files changed

+11
-12
lines changed

lib/usePlacesAutocompleteService.d.ts

+1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
interface usePlacesAutocompleteServiceConfig {
22
apiKey?: string;
3+
libraries?: string[];
34
googleMapsScriptBaseUrl?: string;
45
debounce?: number;
56
options?: google.maps.places.AutocompletionRequest;

lib/usePlacesAutocompleteService.js

+3-3
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,8 @@ function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }
3535

3636
function usePlacesAutocompleteService(_ref) {
3737
var apiKey = _ref.apiKey,
38-
libraries = _ref.libraries,
38+
_ref$libraries = _ref.libraries,
39+
libraries = _ref$libraries === void 0 ? "places" : _ref$libraries,
3940
_ref$googleMapsScript = _ref.googleMapsScriptBaseUrl,
4041
googleMapsScriptBaseUrl = _ref$googleMapsScript === void 0 ? _constants.GOOGLE_MAP_SCRIPT_BASE_URL : _ref$googleMapsScript,
4142
_ref$debounce = _ref.debounce,
@@ -45,8 +46,7 @@ function usePlacesAutocompleteService(_ref) {
4546
sessionToken = _ref.sessionToken,
4647
language = _ref.language;
4748
var languageQueryParam = language ? "&language=".concat(language) : "";
48-
var librariesDefault = libraries ? "".concat(libraries.toString()) : "places";
49-
var googleMapsScriptUrl = "".concat(googleMapsScriptBaseUrl, "?key=").concat(apiKey, "&libraries=").concat(librariesDefault).concat(languageQueryParam);
49+
var googleMapsScriptUrl = "".concat(googleMapsScriptBaseUrl, "?key=").concat(apiKey, "&libraries=").concat(libraries).concat(languageQueryParam);
5050

5151
var _useState = (0, _react.useState)([]),
5252
_useState2 = _slicedToArray(_useState, 2),

lib/usePlacesWidget.js

+3-3
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,8 @@ function usePlacesWidget(props) {
2525
var ref = props.ref,
2626
onPlaceSelected = props.onPlaceSelected,
2727
apiKey = props.apiKey,
28-
libraries = props.libraries,
28+
_props$libraries = props.libraries,
29+
libraries = _props$libraries === void 0 ? "places" : _props$libraries,
2930
_props$inputAutocompl = props.inputAutocompleteValue,
3031
inputAutocompleteValue = _props$inputAutocompl === void 0 ? "new-password" : _props$inputAutocompl,
3132
_props$options = props.options;
@@ -47,8 +48,7 @@ function usePlacesWidget(props) {
4748
var autocompleteRef = (0, _react.useRef)(null);
4849
var observerHack = (0, _react.useRef)(null);
4950
var languageQueryParam = language ? "&language=".concat(language) : "";
50-
var librariesDefault = libraries ? "".concat(libraries.toString()) : "places";
51-
var googleMapsScriptUrl = "".concat(googleMapsScriptBaseUrl, "?libraries=").concat(librariesDefault, "&key=").concat(apiKey).concat(languageQueryParam);
51+
var googleMapsScriptUrl = "".concat(googleMapsScriptBaseUrl, "?libraries=").concat(libraries, "&key=").concat(apiKey).concat(languageQueryParam);
5252
var handleLoadScript = (0, _react.useCallback)(function () {
5353
return (0, _utils.loadGoogleMapScript)(googleMapsScriptBaseUrl, googleMapsScriptUrl);
5454
}, [googleMapsScriptBaseUrl, googleMapsScriptUrl]);

src/usePlacesAutocompleteService.js

+2-3
Original file line numberDiff line numberDiff line change
@@ -6,16 +6,15 @@ import { GOOGLE_MAP_SCRIPT_BASE_URL } from "./constants";
66

77
export default function usePlacesAutocompleteService({
88
apiKey,
9-
libraries,
9+
libraries = "places",
1010
googleMapsScriptBaseUrl = GOOGLE_MAP_SCRIPT_BASE_URL,
1111
debounce = 300,
1212
options = {},
1313
sessionToken,
1414
language,
1515
}) {
1616
const languageQueryParam = language ? `&language=${language}` : "";
17-
const librariesDefault = libraries ? `${libraries.toString()}` : "places";
18-
const googleMapsScriptUrl = `${googleMapsScriptBaseUrl}?key=${apiKey}&libraries=${librariesDefault}${languageQueryParam}`;
17+
const googleMapsScriptUrl = `${googleMapsScriptBaseUrl}?key=${apiKey}&libraries=${libraries}${languageQueryParam}`;
1918
const [placePredictions, setPlacePredictions] = useState([]);
2019
const [isPlacePredsLoading, setIsPlacePredsLoading] = useState(false);
2120
const [placeInputValue, setPlaceInputValue] = useState(null);

src/usePlacesWidget.js

+2-3
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ export default function usePlacesWidget(props) {
88
ref,
99
onPlaceSelected,
1010
apiKey,
11-
libraries,
11+
libraries = "places",
1212
inputAutocompleteValue = "new-password",
1313
options: {
1414
types = ["(cities)"],
@@ -30,8 +30,7 @@ export default function usePlacesWidget(props) {
3030
const autocompleteRef = useRef(null);
3131
const observerHack = useRef(null);
3232
const languageQueryParam = language ? `&language=${language}` : "";
33-
const librariesDefault = libraries ? `${libraries.toString()}` : "places";
34-
const googleMapsScriptUrl = `${googleMapsScriptBaseUrl}?libraries=${librariesDefault}&key=${apiKey}${languageQueryParam}`;
33+
const googleMapsScriptUrl = `${googleMapsScriptBaseUrl}?libraries=${libraries}&key=${apiKey}${languageQueryParam}`;
3534

3635
const handleLoadScript = useCallback(
3736
() => loadGoogleMapScript(googleMapsScriptBaseUrl, googleMapsScriptUrl),

0 commit comments

Comments
 (0)