输入通过验证后,状态不会更新

发布于 2025-02-09 19:52:46 字数 428 浏览 1 评论 0原文

在登录功能(由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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文