老师你好,您在课堂中提到,pureComponent 浅比较只比较对象的第一层数据,但为什么我定义了层次很深的对象,pureComponent也能对比出来呢?changeObjName 函数运行后生效了
class ArrList extends React.PureComponent {
constructor() {
super()
this.state = {
obj: { age: {value: {num: {a: {b:{c:{d:{e:{name: '孙悟空'}}}}}}}} },
}
}
changeObjName = ()=>{
var copy = JSON.parse(JSON.stringify(this.state.obj));
copy.age.value.num.a.b.c.d.e.name = '猪八戒';
this.setState({
obj: copy
})
}
render() {
return <div>
<ul>
<li>
{this.state.obj.age.value.num.a.b.c.d.e.name }
</li>
</ul>
<button onClick={this.changeObjName }>change name</button>
</div>
}
}