【发布时间】:2020-08-11 23:26:22
【问题描述】:
我正在使用material UI构建登录和注册页面,使用useRef返回一个TextFiled引用实例,并使用xxxRef.current.value获取输入值。
我可以顺利运行我的项目,并且可以正确获取value,但是控制台总是提醒我:
Property 'value' does not exist on type 'never'.
这是我的代码sn-ps:
const accountRef = useRef();
<TextField
variant="outlined"
margin="normal"
required
fullWidth
id="account"
label="Account"
name="account"
autoComplete="account"
autoFocus
defaultValue={account}
inputRef={accountRef}
/>
const payload = {
account: accountRef.current?.value ?? '',
password: passwordRef.current?.value ?? '',
nickname: nicknameRef.current?.value ?? '',
};
【问题讨论】:
标签: reactjs typescript ecmascript-6 material-ui react-hooks