Open lasharela opened 2 years ago
my solution was to fork this library and export this function also since it is already there and now it looks like this
import CountryPicker, {
Country,
CountryCode,
FlagButton,
getCountryInfo,
} from '@olegnjadocode/react-native-country-picker-modal'
const initLocalCountry: CountryCode = 'GB'
const [selectedCountry, setSelectedCountry] = useState<Country>()
useEffect(() => {
getCountryInfo({countryCode: initLocalCountry}).then((data) => {
if (data) onSelectCountry(data)
})
}, [])
i guess i could try creating PR here to add this but ive seen that all recent PRs are closed due to inactivity so i dont think it will be accepted, you could try and install your own forked version or use mine https://www.npmjs.com/package/@olegnjadocode/react-native-country-picker-modal
but i also had to modify this function a little as it returns CountryInfo object, not full Country
import CountryPicker, {
getAllCountries,
FlagType,
} from "react-native-country-picker-modal";
useEffect(() => {
async function getCountry() {
const countries = await getAllCountries(FlagType.FLAT);
const country = countries.find(
(country) => country.cca2 === pickerCountryCode
);
setCountry(country);
}
getCountry();
}, []);
import CountryPicker, { getAllCountries, FlagType, } from "react-native-country-picker-modal"; useEffect(() => { async function getCountry() { const countries = await getAllCountries(FlagType.FLAT); const country = countries.find( (country) => country.cca2 === pickerCountryCode ); setCountry(country); } getCountry(); }, []);
nice hack
Is there any way to get the current country that is set by default? I would like to get the whole country object selected by default but won't like to getAllCountries and then filter.
Do we have better way to do so?