在很多时候,react等使用状态机制的框架中,需要根据数据变化来决定是否进行页面的重新渲染,如果是我们认为可控的在特定变化时才进行更新的话,就需要注意:
数组的对比:
存在的问题,数组是引用类型,就会有[]==[]为false的结果,使用应用中,需要返回为true
解决办法:
借用JSON.stringify(),把对象转化成json字符串进行比较,就会得到你想要的结果了!
shouldComponentUpdate(nextProps, nextState) {
return this.props.chartData !== nextProps.chartData || JSON.stringify(this.props.analyseTool) !== JSON.stringify(nextProps.analyseTool);
}