wellyshen/use-places-autocomplete

how do we use setComponentRestrictions for suggesstions base on countries list like ["us", ...]

tabvn opened this issue ยท 5 comments

tabvn commented

i got answer

here is sample for someone need

const {
    ready,
    value,
    suggestions: { status, data },
    setValue,
    clearSuggestions,
  } = usePlacesAutocomplete({
    requestOptions: {
      /* Define search scope here */
      componentRestrictions: { country: ["us", "vn"] },
    },
    debounce: 300,
  });

Not work for me I restrict country but still got results from all over the place

^ same!!

It's because the lib is using values in cache, if you clean up the session storage of the browser it will work as expected.

For now, I'm using this way:

cacheKey: 'br',
requestOptions: {
   componentRestrictions: { country: 'br' },
},

@adisak1618 @bandhanEA

These are my request options that work for addresses in US

requestOptions: {
componentRestrictions: { country: 'us' },
types: ['address']
},
debounce: 300,
cache: 24 * 60 * 60
}