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.

Uncaught Invariant Violation: Maximum update depth exceeded.

这个错查了一下,说是超出最大更新深度。当组件在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.

上一篇:node的二进制权限比对设计


下一篇:Selenium