https://www.jianshu.com/p/33cda0dc316a
Component始终会重新渲染组件
PureComponent只会浅比较
下面这段代码只有Component会更新
test = () => {
let {obj} = this.state;
obj.b.arr.push(6)
this.setState({
obj: newObj
});
console.log(this.state.obj.b.arr)
};
render() {
return (
<div>
<Button onClick={this.test}>test</Button>
<div>{this.state.obj.b.arr}</div>
</div>
)
}
如果想PureComponent也更新用immutability-helper
const newObj = update(obj, {
b: {arr: {$push: [9]}}
});
网友评论