react-phone-input-2 icon indicating copy to clipboard operation
react-phone-input-2 copied to clipboard

Get selected country Code, like 'uk'

Open rijans opened this issue 1 year ago • 1 comments

Any way to get selected country code? like 'uk' on select country?

rijans avatar Mar 10 '23 08:03 rijans

Hi, You can destructure dialCode from data

interface IMaskedInput { dialCode: string; value: string; }

const handlePhoneInputChange = (value: string, data: IMaskedInput) => { console.log(data.dialCode); // +998 };

    <PhoneInput
    country={'uz'}
    autoFormat
    enableSearch
    countryCodeEditable={false}
    onChange={handlePhoneInputChange}
    inputProps={{
      name: PHONENUMBER,
    }}
  />

developer-773 avatar Aug 02 '23 16:08 developer-773