diff --git a/README.md b/README.md index caa1f57..84cc432 100644 --- a/README.md +++ b/README.md @@ -189,6 +189,7 @@ The hook returns an object with properties: - `placesAutocompleteService`: Instance of [AutocompleteService](https://developers.google.com/maps/documentation/javascript/reference/places-autocomplete-service#AutocompleteService) - `placesService`: Instance of [PlacesService](https://developers.google.com/maps/documentation/javascript/reference/places-service#PlacesService) - `autocompleteSessionToken`: Instance of [AutocompleteSessionToken](https://developers.google.com/maps/documentation/javascript/reference/places-autocomplete-service#AutocompleteSessionToken). You can use this to [group several requests into a single session](https://developers.google.com/maps/documentation/places/web-service/session-tokens) +- `refreshSessionToken`: call this function if you need [to refresh the session token](https://developers.google.com/maps/documentation/places/web-service/session-tokens) - `placePredictions`: an array of [AutocompletePrediction](https://developers.google.com/maps/documentation/javascript/reference/places-autocomplete-service#AutocompleteResponse) - `isPlacePredictionsLoading`: sets to true when a `getPlacePredictions` request is being sent and not yet resolved. - `getPlacePredictions: (opt: `[Options](https://developers.google.com/maps/documentation/javascript/reference/places-autocomplete-service#AutocompletionRequest)`): void`: a function which you call whenever you want to request places predictions. Takes one [argument](https://developers.google.com/maps/documentation/javascript/reference/places-autocomplete-service#AutocompleteResponse). diff --git a/lib/usePlacesAutocompleteService.d.ts b/lib/usePlacesAutocompleteService.d.ts index 9e830af..f353d3f 100644 --- a/lib/usePlacesAutocompleteService.d.ts +++ b/lib/usePlacesAutocompleteService.d.ts @@ -22,6 +22,7 @@ interface usePlacesAutocompleteServiceResponse { getQueryPredictions: ( opt: google.maps.places.QueryAutocompletionRequest ) => void; + refreshSessionToken: () => void; } export default function usePlacesAutocompleteService( diff --git a/lib/usePlacesAutocompleteService.js b/lib/usePlacesAutocompleteService.js index 5ef2cbe..e2ccd58 100644 --- a/lib/usePlacesAutocompleteService.js +++ b/lib/usePlacesAutocompleteService.js @@ -154,6 +154,9 @@ function usePlacesAutocompleteService(_ref) { setQueryInputValue(null); debouncedQueryPredictions(opt); setIsQueryPredsLoading(false); + }, + refreshSessionToken: function refreshSessionToken() { + autocompleteSession.current = new google.maps.places.AutocompleteSessionToken(); } }; } \ No newline at end of file diff --git a/package.json b/package.json index 45ac789..973b11a 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "react-google-autocomplete", - "version": "2.5.0", + "version": "2.6.0", "description": "React component for google autocomplete.", "main": "index.js", "types": "index.d.ts", diff --git a/src/usePlacesAutocompleteService.d.ts b/src/usePlacesAutocompleteService.d.ts index 9e830af..f353d3f 100644 --- a/src/usePlacesAutocompleteService.d.ts +++ b/src/usePlacesAutocompleteService.d.ts @@ -22,6 +22,7 @@ interface usePlacesAutocompleteServiceResponse { getQueryPredictions: ( opt: google.maps.places.QueryAutocompletionRequest ) => void; + refreshSessionToken: () => void; } export default function usePlacesAutocompleteService( diff --git a/src/usePlacesAutocompleteService.js b/src/usePlacesAutocompleteService.js index 9d9eae3..5c06852 100644 --- a/src/usePlacesAutocompleteService.js +++ b/src/usePlacesAutocompleteService.js @@ -132,5 +132,9 @@ export default function usePlacesAutocompleteService({ debouncedQueryPredictions(opt); setIsQueryPredsLoading(false); }, + refreshSessionToken: () => { + autocompleteSession.current = + new google.maps.places.AutocompleteSessionToken(); + }, }; }