输入通过验证后,状态不会更新
在登录功能(由OnClick触发)中,我使用的是验证功能,该功能测试了输入中的电子邮件并返回布尔值。如果电子邮件未第一次通过验证,那么在下一次尝试中即使输入有效,错误状态未更新。
const handleLogin = async () => {
const emailValid = validateEmail(email);
console.log(emailValid)
if (emailValid) {
setError('')
const response = await getAuthToken();
localStorage.setItem('OauthToken',response.access_token)
} else {
setError("Invalid Email")
console.log(error)
}
}
Inside a Login function (which is triggered by an onClick), I'm using a validation function which tests the email from the input and returns a boolean. If the email doesn't pass the validation the first time, on the next try even if the input is valid the error state doesn't get updated.
const handleLogin = async () => {
const emailValid = validateEmail(email);
console.log(emailValid)
if (emailValid) {
setError('')
const response = await getAuthToken();
localStorage.setItem('OauthToken',response.access_token)
} else {
setError("Invalid Email")
console.log(error)
}
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论