ErrorPro / react-google-autocomplete

React components for google places API.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Is it possible to change country dynamically?

png-prakash opened this issue · comments

import useGoogle from "react-google-autocomplete/lib/usePlacesAutocompleteService";

import Constants from '../../lib/Constants';

const GoogleAddress = (props) => {
  const [value, setValue] = useState("");
  const {placesService, placePredictions, getPlacePredictions} = useGoogle({
    apiKey: Constants.GOOGLE_ADDRESS_API_KEY,
    options: {
      componentRestrictions: { country: props.country },
    },
  });

When change the country in dropdown list is possible to get the addresses based on that particular country?

@png-prakash You have two options:

  1. Lazy load the react component, so the initial value come from the previously selected country.
  2. You separately save in a useState const the options.

const [autocompleteOptions, setAutocompleteOptions] = useState({ componentRestrictions: { country: "cl" }, types: ["address"], })