React js-如何在更改国家代码后重置React-phone-input-2输入



所以我需要在更改国家/地区后重置输入值,但它保持相同的值,我使用的是react功能组件,我在这一点上被卡住了

这是我在下面的代码

<PhoneInput
country={ip.toLocaleLowerCase()}
value={phone}
countryCodeEditable={false}
specialLabel={""}
enableSearch={true}
masks={phoneFormat}
searchPlaceholder={""}
placeholder={t("register:phone")}
inputStyle={{
paddingTop: 26,
paddingRight: 14,
paddingBottom: 26,
paddingLeft: 58,
width: "100%",
zIndex: 1,
backgroundColor: "#F3F6F9",
border: "none",
}}
onChange={(e) => {
setPhone(e);
setErrors({ ...errors, phone: false });
}}

感谢回答

ip是否存储在某个状态中?您可能在某个地方有一个const [ip, setip] = useState(),然后在上面的更改处理程序中将ip设置为:

onChange={(e) => {
setPhone(e);
setErrors({ ...errors, phone: false });
setIp(e.target.value)
}}

最新更新