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

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

相关文章:

  • 2021-12-20
  • 2021-07-21
  • 2022-12-23
  • 2021-12-21
  • 2022-12-23
  • 2021-09-27
猜你喜欢
  • 2022-01-17
  • 2021-09-10
  • 2022-12-23
  • 2021-05-20
  • 2022-02-25
  • 2022-12-23
  • 2021-07-10
相关资源
相似解决方案