簡體   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