繁体   English   中英

无法通过在 React 中使用 const email= event.target.email.value 获取用户电子邮件来发送密码重置邮件

[英]Cannot send password reset mail by getting user email with const email= event.target.email.value in React

有没有办法通过获取用户电子邮件来发送以下密码重置邮件,const email = event.target.email.value,我试过但由于异步功能,我无法传递事件参数? 仅供参考 - 我正在使用反应挂钩发送密码重置邮件。 下面的代码截图供您参考。

最后,我在这里使用了 useRef 来发送重置邮件。 如何将事件作为参数传递给异步函数以发送密码重置邮件?

我的代码:

const [sendPasswordResetEmail, 发送] = useSendPasswordResetEmail(auth);

const handleSubmit = event => {
    event.preventDefault();
    const email = event.target.email.value;
    const password = event.target.password.value;
    signInWithEmailAndPassword(email, password)
}

if (loading || sending) {
    return <Loading></Loading>
}

let from = location.state?.from?.pathname || "/";
let loginError;

const navigateRegister = () => {
    navigate('/register')
}

const resetPassword = async () => {
    const email = emailRef.current.value;
    await sendPasswordResetEmail(email);
    if (email) {
        toast('Sent email');
    } else {
        toast('please enter your email address!!')
    }
}

代码截图

尝试使用emailRef.current.value来获取电子邮件,如代码中的resetPassword

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM