【发布时间】:2021-03-02 21:48:22
【问题描述】:
这是我在函数组件中使用的代码
useEffect(() => {
const unsubscribe = firebase.auth().onAuthStateChanged(user => {
setIsLoggedIn(!!user);
});
return () => {
unsubscribe();
};
});
这是我对类组件的尝试。
componentDidUpdate(
prevProps: LessonDrawerProps,
prevState: LessonDrawerState
) {
firebase.auth().onAuthStateChanged(user => {
if (user) {
this.setState({
isLoggedIn: true,
});
}
});
}
类 onAuthStateChanged 检测没有像函数组件中那样正常工作。
如何做到这一点?
【问题讨论】:
标签: reactjs typescript firebase firebase-authentication