catamphetamine / react-phone-number-input

React component for international phone number input
http://catamphetamine.gitlab.io/react-phone-number-input/
MIT License
924 stars 194 forks source link

How to get the country calling code when calling onCountryChange? #423

Closed vijinpaulraj closed 1 year ago

vijinpaulraj commented 1 year ago

First of all, thanks for all your hard work trying to keep this component bug-free. In my project, the requirement is to extract the country calling code when the country dropdown changes. For that I'm relying upon the "onCountryChange” handler which returns the ISO country code. However, I need to extract the calling code instead. For instance, for GB it should return 44 or +44.

I have ended up using the getCountryCallingCode() to get the corresponding calling code of the country. For example, getCountryCallingCode(‘GB') // returns 44.

Although I have achieved what I wanted, I’m just wondering, Is it possible to return an object with the country and calling code onCountryChange. Something like, { country: 'GB', callingCode: '44' }

The ask is similar to this - #294

catamphetamine commented 1 year ago

No, since it already works. Use the function you've mentioned in your post.