@ttoss/google-maps 2.0.7 → 2.0.8
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/esm/index.js +20 -20
- package/package.json +3 -3
package/dist/esm/index.js
CHANGED
|
@@ -172,7 +172,15 @@ var useMap = (options = {}) => {
|
|
|
172
172
|
};
|
|
173
173
|
|
|
174
174
|
// src/usePlacesAutocomplete/index.ts
|
|
175
|
+
import * as React6 from "react";
|
|
176
|
+
|
|
177
|
+
// src/usePlacesAutocomplete/useLatest.ts
|
|
175
178
|
import * as React5 from "react";
|
|
179
|
+
var useLatest = val => {
|
|
180
|
+
const ref = React5.useRef(val);
|
|
181
|
+
ref.current = val;
|
|
182
|
+
return ref;
|
|
183
|
+
};
|
|
176
184
|
|
|
177
185
|
// src/usePlacesAutocomplete/debounce.ts
|
|
178
186
|
var debounce = (fn, delay) => {
|
|
@@ -188,14 +196,6 @@ var debounce = (fn, delay) => {
|
|
|
188
196
|
};
|
|
189
197
|
var debounce_default = debounce;
|
|
190
198
|
|
|
191
|
-
// src/usePlacesAutocomplete/useLatest.ts
|
|
192
|
-
import { useRef } from "react";
|
|
193
|
-
var useLatest_default = val => {
|
|
194
|
-
const ref = useRef(val);
|
|
195
|
-
ref.current = val;
|
|
196
|
-
return ref;
|
|
197
|
-
};
|
|
198
|
-
|
|
199
199
|
// src/usePlacesAutocomplete/index.ts
|
|
200
200
|
var usePlacesAutocomplete = ({
|
|
201
201
|
requestOptions,
|
|
@@ -206,21 +206,21 @@ var usePlacesAutocomplete = ({
|
|
|
206
206
|
defaultValue = "",
|
|
207
207
|
initOnMount = true
|
|
208
208
|
} = {}) => {
|
|
209
|
-
const [ready, setReady] =
|
|
210
|
-
const [value, setVal] =
|
|
211
|
-
const [suggestions, setSuggestions] =
|
|
209
|
+
const [ready, setReady] = React6.useState(false);
|
|
210
|
+
const [value, setVal] = React6.useState(defaultValue);
|
|
211
|
+
const [suggestions, setSuggestions] = React6.useState({
|
|
212
212
|
loading: false,
|
|
213
213
|
status: "",
|
|
214
214
|
data: []
|
|
215
215
|
});
|
|
216
|
-
const asRef =
|
|
217
|
-
const requestOptionsRef =
|
|
216
|
+
const asRef = React6.useRef(null);
|
|
217
|
+
const requestOptionsRef = useLatest(requestOptions);
|
|
218
218
|
const {
|
|
219
219
|
google
|
|
220
220
|
} = useGoogleMaps();
|
|
221
|
-
const googleMapsRef =
|
|
221
|
+
const googleMapsRef = useLatest(google.maps);
|
|
222
222
|
const upaCacheKey = cacheKey ? `upa-${cacheKey}` : "upa";
|
|
223
|
-
const init =
|
|
223
|
+
const init = React6.useCallback(() => {
|
|
224
224
|
if (asRef.current) {
|
|
225
225
|
return;
|
|
226
226
|
}
|
|
@@ -237,19 +237,19 @@ var usePlacesAutocomplete = ({
|
|
|
237
237
|
asRef.current = new placesLib.AutocompleteService();
|
|
238
238
|
setReady(true);
|
|
239
239
|
}, [google.maps]);
|
|
240
|
-
const clearSuggestions =
|
|
240
|
+
const clearSuggestions = React6.useCallback(() => {
|
|
241
241
|
setSuggestions({
|
|
242
242
|
loading: false,
|
|
243
243
|
status: "",
|
|
244
244
|
data: []
|
|
245
245
|
});
|
|
246
246
|
}, []);
|
|
247
|
-
const clearCache =
|
|
247
|
+
const clearCache = React6.useCallback(() => {
|
|
248
248
|
try {
|
|
249
249
|
sessionStorage.removeItem(upaCacheKey);
|
|
250
250
|
} catch (error) {}
|
|
251
251
|
}, []);
|
|
252
|
-
const fetchPredictions =
|
|
252
|
+
const fetchPredictions = React6.useCallback(debounce_default(val => {
|
|
253
253
|
if (!val) {
|
|
254
254
|
clearSuggestions();
|
|
255
255
|
return;
|
|
@@ -300,13 +300,13 @@ var usePlacesAutocomplete = ({
|
|
|
300
300
|
}
|
|
301
301
|
});
|
|
302
302
|
}, debounce2), [debounce2, clearSuggestions]);
|
|
303
|
-
const setValue =
|
|
303
|
+
const setValue = React6.useCallback((val, shouldFetchData = true) => {
|
|
304
304
|
setVal(val);
|
|
305
305
|
if (asRef.current && shouldFetchData) {
|
|
306
306
|
fetchPredictions(val);
|
|
307
307
|
}
|
|
308
308
|
}, [fetchPredictions]);
|
|
309
|
-
|
|
309
|
+
React6.useEffect(() => {
|
|
310
310
|
if (!initOnMount) {
|
|
311
311
|
return () => {
|
|
312
312
|
return null;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ttoss/google-maps",
|
|
3
|
-
"version": "2.0.
|
|
3
|
+
"version": "2.0.8",
|
|
4
4
|
"license": "MIT",
|
|
5
5
|
"author": "ttoss",
|
|
6
6
|
"contributors": [
|
|
@@ -36,8 +36,8 @@
|
|
|
36
36
|
"jest": "^29.7.0",
|
|
37
37
|
"react": "^18.3.1",
|
|
38
38
|
"tsup": "^8.3.0",
|
|
39
|
-
"@ttoss/
|
|
40
|
-
"@ttoss/
|
|
39
|
+
"@ttoss/config": "^1.34.1",
|
|
40
|
+
"@ttoss/test-utils": "^2.1.17"
|
|
41
41
|
},
|
|
42
42
|
"keywords": [
|
|
43
43
|
"Google",
|