Uncaught Invariant Violation: Maximum update depth exceeded.

Uncaught Invariant Violation: Maximum update depth exceeded. This can happen when a component repeatedly calls setState inside componentWillUpdate or componentDidUpdate. React limits the number of nested updates to prevent infinite loops.

这个错查了一下,说是超出最大更新深度。当组件在componentWillUpdate或componentDidUpdate中重复调用setState时,可能会发生这种情况。React限制嵌套更新的数量以防止无限循环。

错误代码:

<div className="tableBody">
   {equipmentsList && equipmentsList.map((item, index) => {
      return <div key={index}>
         <div className="tableTd">{index+1}</div>
            <div className="tableTd equipmentTd" onClick={this.showDetails(item.equipmentNum)}>{item.equipmentName}</div>
         </div>;
      })
    }
</div>
  showDetails = (equipmentNum) => {
      this.setState({
        detailVisible: true,
        equipmentNum
      })
  }

问题就出现在

onClick={this.showDetails(item.equipmentNum)}

正常写法:

onClick={() => this.showDetails(item.equipmentNum)}

加上一个()=> 就可以了

posted @ 2021-08-10 11:08  rachelch  阅读(851)  评论(0编辑  收藏  举报