react-native-phone-number-input
react-native-phone-number-input copied to clipboard
Unable to set defaultValue and format number
We tried setting the default value of the phone with value or defaultValue but it doesn't seem to work but passing them to textProps={{value: phone}}
does work but then autoFormat
doesn't unless focused on input.
Also, some functions like setValue return an undefined error, can you make some examples with those?
Thanks!
I'm using this, still no luck with defautValue
const [phone, setPhone] = useState('');
...
DeviceInfo.getPhoneNumber().then((phoneNumber) => {
if (__DEV__) {
console.log('Got phone number:', phoneNumber);
}
if (typeof phoneNumber !== 'undefined' || phoneNumber !== '') {
setPhone(phoneNumber);
console.log(phone);
// phoneInput.current?.focus();
}
});
};
It gets the phone number say +1323000000 in this case and then I have defaultValue={phone}