garganurag893 / react-native-phone-number-input

React Native component for phone number.
MIT License
372 stars 212 forks source link

Cant change value with onChangeText #118

Closed shellord closed 1 year ago

shellord commented 2 years ago

Cant change value with onChangeValue.

const [value,setValue] = useState('')
 <PhoneInput
...
  value = {value}
  onChangeText={()=>setValue('something'+value) }
...
}

this doesnt work

bharathibtch commented 1 year ago

the value and default value is not working, but you can use the textInputProps like below

  const [phoneInputState, setPhoneInputState] = useState<string>("0000");

      <PhoneInput
        textInputProps={{
          value: phoneInputState
        }}

onChangeText change the state value: 

  function onChangePhoneNumber(text: string) {
   // allowed only numbers ..  or whatever you want. 
    const value = text.replace(/\D/g, "");
    setPhoneInputState(value);
  }
taiqmachandshawale commented 11 months ago

Thanks for the solutions.