xcarpentier / react-native-country-picker-modal

🇦🇶 Country picker provides a modal allowing a user to select a country from a list. It display a flag next to each country name.
https://reactnative.gallery/xcarpentier/country-picker
MIT License
1.08k stars 802 forks source link

How to get the country name from the two letters code ? #354

Closed MorganeAlinai closed 4 years ago

MorganeAlinai commented 4 years ago

Hi,

I use your plugin to select the country for our users.

I store two letter codes like "FR".

At some point in the UI, I need to transform that "FR" into "France".

I've seen in the code that you have the method for that, but it don't seem to be exported, unless I miss something.

It's my first app so I may be asking a stupid question but, is there a way to get this method in my code ?

Thanks

stale[bot] commented 4 years ago

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

BohdanRozov commented 3 years ago

This is how I do it

    useEffect(() => {
      const getCorrectCountry = async () => {
        const allCountries = await getAllCountries(FlagType.FLAT); // import getAllCountries from this library
        const country = allCountries.find((item) => item.cca2 === twoLettersCode);
        if (country?.name) {
          setCountryName(country.name.toString());
        }
      };
      getCorrectCountry();
    }, []);