首页 > 其他 > 详细

Uncaught Invariant Violation: Maximum update depth exceeded.

时间:2021-08-10 12:22:13      阅读:18      评论:0      收藏:0      [点我收藏+]

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)}

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

Uncaught Invariant Violation: Maximum update depth exceeded.

原文:https://www.cnblogs.com/rachelch/p/15122761.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!