1 回答
1
有很多方法可以做到这一点。您没有检查输入是否为空。许多方法之一是 - 您可以使用useref
import { useRef } from 'react';
const inputRef = useRef();
<input ref={inputRef} type="text" required />
const handleSubmit = (e: any) => {
if (inputRef.current.value) {
alert('submitting')
}
else {
alert('empty input')
}
}
于 2020-11-04T12:43:02.067 回答