【发布时间】:2021-04-05 03:55:30
【问题描述】:
我正在尝试在 Firebase 注册完成后导航到另一个页面,因此我尝试在注册成功后使用 useHistory 挂钩导航到下一页 注册成功但钩子不起作用,控制台没有显示任何错误
如果钩子在这种情况下不起作用,如果注册成功,我如何导航到下一页?
import {useHistory} from 'react-router-dom'
const history = useHistory();
function signup(event) {
console.log({email, password});
firebase.auth().createUserWithEmailAndPassword(email, password)
.then((user) => {
// Signed in
// ...
this.history.push('/Quiz')
console.log(email, password)
firebase.database().ref('users/' + user.uid).set({ email: user.email, password: user.password });
})
.catch((error) => {
var errorCode = error.code;
var errorMessage = error.message;
// ..
console.log(errorMessage)
});
}
【问题讨论】:
-
使用
history.push('/Quiz')而不是this.history.push('/Quiz') -
也没用
-
它给出了错误“react hooks can't be used inside callbacks”
-
检查this answer,这可能会有所帮助
-
试试
console.log(error.message)
标签: reactjs firebase react-router react-hooks react-functional-component