【发布时间】:2021-01-31 20:15:28
【问题描述】:
我有问题 使用 React 和 TS
我在美国有电子邮件和密码的状态
const emailRef = useRef<string | null>(null);
const passwordRef = useRef<string | null>(null);
像这样设置它们:
const onEmailChange = (value: any) => {
emailRef.current = value;
};
const onPasswordChange = (value: any) => {
passwordRef.current = value;
};
并尝试使用它们的 onButtonEnter 函数对接得到这个问题:
const onButtonEnter = () => {
if (!buttonDisabled) {
setButtonDisabled(true);
if (emailRef === '' && passwordRef === '') { - here I have an issue
showAlert(errors.invalid);
!!!此条件将始终返回 'false',因为类型 'MutableRefObject
它可能是什么?
【问题讨论】:
-
您正在比较对 DOM 元素的引用和字符串,这没有意义。
标签: javascript reactjs typescript