关于reactjs 警告出现死循环问题

警告提示语:
Cannot update during an existing state transition (such as within render or another component's constructor). Render methods should be a pure function of props and state; constructor side-effects are an anti-pattern, but can be moved to componentWillMount.

点击查询按钮请求接口获取表格数据完后setState给Table,最后页面渲染出来,完后浏览器控制台出现一堆死循环提示的警告,直到内存溢出浏览器页面崩溃
百度过了解决方法,也按照他们的方法去解决,最后还是不行

fetchDatas = () => {
  ...
  this.setState({columns, dataSource: content});
}


<Button type="primary"  onClick={()=>{this.fetchDatas()}}>查询</Button>

<Table loading={loading} onRow={this.onRow} rowKey={(record, index) => index} dataSource={dataSource} columns={columns} pagination={false} scroll={{x: 1000, y: 500}} />
阅读 3.6k
2 个回答

antd真是有点坑,浏览器控制台提示不推荐使用onRowClick,推荐使用onRow,我用了onRow 后就出现一堆死循环的警告,直到浏览器崩溃,后面把onRow 换回onRowClick就正常了

Warning: onRowClick is deprecated, please use onRow instead.

setState 是不保证同步的,是不保证同步的,是不保证同步的。重要的事情说三遍,楼主可以根据这个去找原因

撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进
推荐问题