当前位置: 代码迷 >> 综合 >> React 报错 Too many re-renders. React limits the number of renders to prevent an infini
  详细解决方案

React 报错 Too many re-renders. React limits the number of renders to prevent an infini

热度:95   发布时间:2024-01-21 01:56:12.0

写hooks遇到的,大概率是this的问题,
标签里写成箭头函数

<button onClick={
    () => setCounter(counter + 1)}>+1</button>

或者用bind绑定this

onClick={
    increment.bind(this)}

建议用第一种

如果解决了给个赞吧!

  相关解决方案