I am using react-native-phone-number-input in my project. I am also using formik inside it
Below is my code:
const textChangeHandler = (text: any) => {
var getCode = phoneInput.current?.getCallingCode();
var getText = '+' + getCode + text;
form.setFieldTouched(field.name);
form.setFieldValue(field.name, getText);
console.log('>>', getText);
if (onUpdate) {
onUpdate(getText);
}
};
<PhoneInput
ref={phoneInput}
defaultValue={''}
defaultCode="US"
layout="first"
onChangeCountry={value => {
textChangeHandler(value);
}}
onChangeText={textChangeHandler}
autoFocus
/>
I have to pass the written number with country code into form.setFieldValue. It is working fine if I select country first and then write my number, if I do this then I am getting >> +11234567890 in console. But if I write the number first and then select country the I am getting >> +1[object Object].
I am not able to figure out where I am making mistake.