We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
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 this plugin compatible with Angular 17 for mobile?
Its strange how it works on desktop
The text was updated successfully, but these errors were encountered:
I fixed it this way:
const getCountries = async () => { const Country = await import('country-state-city/lib/country'); const {getAllCountries} = Country.default; return getAllCountries().sort((a, b) => a.name.localeCompare(b.name)); }; const getCities = async (country: string, state?: string) => { const City = await import('country-state-city/lib/city'); const {getCitiesOfState, getCitiesOfCountry} = City.default; return state ? getCitiesOfState(country, state) : getCitiesOfCountry(country) ?? []; }
Since it's now async, becomes troublesome as need to run a side affect in react, so used a hook:
import { ICity, ICountry, IState } from 'country-state-city/lib/interface'; export const useCountriesAndCities = (props?: { country?: string, state?: string }) => { const [countries, setCountries] = useState<ICountry[]>([]); const [cities, setCities] = useState<ICity[]>([]); useEffect(() => { getCountries().then(setCountries); }, []); useEffect(() => { if (props?.country && props?.state) { getCities(props.country, props.state).then(setCities); } }, [props?.country, props?.state]); const phoneCodes = useMemo(() => countries .map((country) => ({ value: country.phonecode.startsWith('+') ? country.phonecode : `+${country.phonecode}`, label: `${country.flag} ${ country.phonecode.startsWith('+') ? country.phonecode : `+${country.phonecode}` }`, })) .filter((a, i, arr) => arr.findIndex((b) => b.value === a.value) === i), [countries]); return { countries, cities, phoneCodes }; };
Related: #184 #123
Sorry, something went wrong.
No branches or pull requests
Is this plugin compatible with Angular 17 for mobile?
Its strange how it works on desktop
The text was updated successfully, but these errors were encountered: