Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Is it possible to change country dynamically? #216

Open
png-prakash opened this issue Jun 28, 2023 · 1 comment
Open

Is it possible to change country dynamically? #216

png-prakash opened this issue Jun 28, 2023 · 1 comment

Comments

@png-prakash
Copy link

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?

@danielc1015
Copy link

@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"], })

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants