React 的 shouldComponentUpdate

在react的生命周期中,做优化的话,可以选择在shouldComponetUpdate这里选择render的条件。

但是也有一个坑。这是我写的一个方法。

/**
* 主要处理批量操作
* @params {Object:nextProps}
* */
shouldComponetUpdate(nextProps) {
if (nextProps.removeBatchList.length === 0) {
this.setState({
selectedRowKeys: []
});
}
}
会无限循环,然后崩溃。
所以,不要在这个生命周期里使用this.setState()
可以选择在componentWillReceiveProps(nextProps)这里用
posted @ 2018-08-21 17:10  空杉心雨后  阅读(716)  评论(0编辑  收藏  举报