rili-live / react-native-phone-input

Phone input box for React Native
https://www.npmjs.com/package/react-native-phone-input
MIT License
42 stars 54 forks source link

Setting initialCountry using state #48

Open ravindra-encoresky opened 1 year ago

ravindra-encoresky commented 1 year ago

I'm facing this problem : trying to pre-set initialCountry but it doesn't work. It shows US flag every time.

        <PhoneInput
            style={{ width: wp('10%'), height: wp('10%') }}
            textProps={{
              placeholder: '',
              fontSize: hp('1.7991%'),
            }}
            initialCountry={this.state.initialCountry}
            ref={this.props.setPhoneRef}
            onPressFlag={() => {
              this.props.onPressFlag();
            }}
          />

Can anyone please share how can I achieve this or if this feature still needs to be developed.

thanks.

ishanVaghasiya commented 7 months ago

I have also faced the same problem. but the solution below works for me.

use set your initial country code as initialValue props

for ex. if I want to set India as the default country

<PhoneInput
            ref={phoneRef}
            initialCountry={'in'}   <---- not working in my case
            initialValue="91"    <--- I have do this 
            textProps={{
                placeholder: 'Enter a phone number...'
            }}
        />