【发布时间】:2019-10-25 16:11:15
【问题描述】:
代码运行良好,但不知从何而来。
我尝试将条件切换到componentDidMount,但这也不起作用。得到这个函数的错误。
componentDidUpdate() {
if (
this.props.firebase.auth.currentUser &&
this.props.firebase.auth.currentUser.userProfile &&
!this.state.userProfile
) {
this.setState(
{
userProfile: this.props.firebase.auth.currentUser.userProfile
.userProfile
}
);
}
}
它应该将用户重定向到下一个页面,但给我一个“超出最大更新深度”的错误。
【问题讨论】:
-
this.props.firebase.auth.currentUser.userProfile.userProfile,你在currentUser.userProfile里面有userProfile吗? -
来自文档 ->
You may call setState() immediately in componentDidUpdate() but note that it must be wrapped in a condition您的情况需要与prevProps.. reactjs.org/docs/react-component.html#componentdidupdate进行比较
标签: javascript reactjs firebase debugging npm