I want to clear the state of Phone Input component before moving to the next screen. But It is clearing the state in console.log() but not in the PhoneInput component. I have paste my sample code also.
import React, { useState, useRef } from "react";
import { View, Button, Alert } from "react-native";
import { TextInput } from "react-native-paper";
import PhoneInput from "react-native-phone-number-input";
you can clear the state like first you have to create a ref for phoneInput const phoneInput = useRef(null); then use this method phoneInput.current?.setState({
number: '',
});
I want to clear the state of Phone Input component before moving to the next screen. But It is clearing the state in console.log() but not in the PhoneInput component. I have paste my sample code also.
import React, { useState, useRef } from "react"; import { View, Button, Alert } from "react-native"; import { TextInput } from "react-native-paper"; import PhoneInput from "react-native-phone-number-input";
const YourComponent = () => { const [phoneNumber, setPhoneNumber] = useState(""); const [texts, setText] = useState(""); const [formattedNumber, setFormattedNumber] = useState("");
const clearPhoneNumber = () => { setPhoneNumber(""); setText(""); setFormattedNumber(""); console.log(
phone Number :${phoneNumber}
); console.log(formatted:${formattedNumber}
);};
return (
); };
export default YourComponent;