Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/database/10.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript “如何修复”;超过最大更新深度。在componentWillUpdate或componentDidUpdate内调用setState。”;反应中的错误?_Javascript_Reactjs_Firebase_Debugging_Npm - Fatal编程技术网

Javascript “如何修复”;超过最大更新深度。在componentWillUpdate或componentDidUpdate内调用setState。”;反应中的错误?

Javascript “如何修复”;超过最大更新深度。在componentWillUpdate或componentDidUpdate内调用setState。”;反应中的错误?,javascript,reactjs,firebase,debugging,npm,Javascript,Reactjs,Firebase,Debugging,Npm,代码运行得很好,但不知从何而来 我尝试将条件切换到componentDidMount,但也没有成功。获取此函数的错误 componentDidUpdate() { if ( this.props.firebase.auth.currentUser && this.props.firebase.auth.currentUser.userProfile && !this.state.userProfile ) {

代码运行得很好,但不知从何而来

我尝试将条件切换到
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
        }
      );
    }
  }

它应该将用户重定向到下一页,但给我一个错误“超过最大更新深度”。

为什么有.userProfile.userProfile?您可能正在使用未定义的更新userProfile,因此您的
失败了!此.state.userProfile
检查


我将删除第二个.userProfile。

您没有将
prevProps
传递给
组件diddupdate
,然后在您的条件中使用它。如果没有关于您为什么使用userProfile的更多信息,我建议您执行以下操作:

componentDidUpdate(prevProps){
   if(this.props.firebase.auth.currentUser === this.prevProps.firebase.auth.currentUser) {
   ///your code
}}

this.props.firebase.auth.currentUser.userProfile&&的逻辑!此.state.userProfile
似乎不应位于此方法中,因为如果您比较
currentUser
是否仍然存在以及组件更新后是否相同,则它似乎是多余的。

this.props.firebase.auth.currentUser.userProfile.userProfile
,您是否在
currentUser.userProfile
中有
userProfile
?从文档->
中,您可以在componentDidUpdate()中立即调用setState(),但请注意,它必须包装在一个条件中
您的条件需要与
prevProps
进行比较。。