javascript - 未定义的 handleSubmit 函数登录表单
问题描述
我正在做一个带有反应的登录表格。我正在使用事件侦听器来提交表单。我创建了一个在表单标记中调用的 handleSubmit 函数,但是由于某种原因它无法访问函数 handleSubmit。它是未定义的。
这是我的代码:
export default function Signin() {
const [formData, setFormData] = useState({
email: '',
password: '',
successMsg: false,
errorMsg: false,
Loading: false,
})
//data destructuration
const { email, password, successMsg, errorMsg, Loading } = formData;
//Event handlers
const handleChange = evt =>{
//console.log(evt);
setFormData({
...formData,
[evt.target.name] : evt.target.value
});
const handleSubmit = evt => {
evt.preventDefault();
console.log(formData)
};
}
return (
<div className='signin-background'>
<div className='row vh-100 px-5'>
<div className='col-md-5 mx-auto align-self-center' >
{JSON.stringify(formData)}
<form onSubmit={handleSubmit}>
<h3 className='title'>Sign In</h3>
<div className="form-group">
<input onChange={handleChange} value={email} name='email' type="email" className="form-control" placeholder="Enter email" />
</div>
<div className="form-group">
<input onChange={handleChange} value={password} name='password' type="password" className="form-control" placeholder="Enter password" />
</div>
<div className="form-group">
<div className="custom-control custom-checkbox">
<input type="checkbox" className="custom-control-input" id="customCheck1" />
<label className="custom-control-label" htmlFor="customCheck1">Remember me</label>
</div>
</div>
<button type="submit" className="btn btn-primary btn-block">Submit</button>
<p className="forgot-password text-right">
Forgot <Link to='/resetPassword'>password?</Link>
</p>
</form>
</div>
</div>
</div>
)
}
解决方案
推荐阅读
- spring-boot - 在 Spring Boot 应用程序中创建 TCP 客户端以发送和接收
- c++ - 如何使用 boost.log 的记录器?
- javascript - 机器重启后 pm2 托管进程处于错误状态
- java - 如何在 micronaut 中获取当前主机和端口?
- android - 为远程配置设置本地化默认值
- python - 如何将熊猫数据框更改为二进制矩阵?
- sql - Oracle SQL 选择最早时间的日期时间
- html - 组内具有拖放功能的多个列表
- angularjs - WebStorm:显示未使用的 AngularJS 依赖项
- json - SonataAdminBundle json_array 字段给出 INVALID MODE / 字符串转换错误