【发布时间】:2020-12-02 18:35:42
【问题描述】:
我正在尝试按照材料 ui 电话号码的说明进行反应,使用材料 ui 进行反应。在onChange 上,我调用handlePhone 函数,它将输入的值保存到状态。问题是,在每个setPhone 上,它都会禁用输入,就像它使输入失去焦点一样,您每次都必须单击输入才能输入。如果我删除setPhone(value);,它在里面的类型很好,但是我不会保存值并丢失验证。有什么想法吗?
js:
const [phone, setPhone] = React.useState("");
const [phoneError, setPhoneError] = React.useState(false);
const handlePhone = (value, countrydata) => {
setPhoneError(false);
setPhone(value);
html:
<MuiPhoneNumber fullWidth defaultCountry={"es"} variant="outlined" label="Número de teléfono" name="phone" onChange={handlePhone} error={phoneError} helperText={phoneError && "Invalid phone"} value={phone} />
【问题讨论】:
标签: javascript reactjs material-ui next.js