1 回答

TA貢獻(xiàn)1866條經(jīng)驗(yàn) 獲得超5個(gè)贊
這是我遇到的一個(gè)超級(jí)菜鳥錯(cuò)誤,但我沒有使用 useEffect 來(lái)設(shè)置用戶名,而是將 setUserName 狀態(tài)傳遞給我的注冊(cè)組件,并完全取消了 useEffect。這解決了一切。
const onSubmit = async (data) => {
auth
.createUserWithEmailAndPassword(data.email, data.password)
.then((result) => {
result.user.updateProfile({
displayName: data.username,
});
// This is the state i was missing.
setUserName(data.username);
setUserError(!userError);
window.localStorage.setItem('emailForSignIn', data.email);
setRedirect(true);
})
添加回答
舉報(bào)