警告提示语:
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}} />
antd真是有点坑,浏览器控制台提示不推荐使用onRowClick,推荐使用onRow,我用了onRow 后就出现一堆死循环的警告,直到浏览器崩溃,后面把onRow 换回onRowClick就正常了