OpenBookPrices / country-data

Country related data such as ISO codes, currencies etc
MIT License
512 stars 166 forks source link

Could you add some info as to how to use it with React JS? #66

Open nonopolarity opened 7 years ago

nonopolarity commented 7 years ago

the full question on: http://stackoverflow.com/questions/43144036/in-react-how-to-convert-country-code-to-country-name-using-country-data

It is:

I thought I could do

npm install --save country-data

and then in the code:

import CountryData from "country-data";

and use

CountryData.countries["TW"]

to get the country data, and

CountryData.countries["TW"].name

to get the name. But CountryData.countries["TW"] gets undefined already. How can it be done?

gregaubert commented 7 years ago

Are you using webpack with your react project ? Maybe here is the solution : https://github.com/OpenBookPrices/country-data#using-with-webpack

evdb commented 7 years ago

This is odd. Please could you create a test case that fails that I can look at. Your use case is so simple it should work, so I think it must be something in the React setup that is causing trouble. I've no experience with that.

Use an online code bin or better yet fork the repo and create a failing test case (if that is possible).