About whether or not under react to refresh the page manually determine the method

Recently encountered a problem in the development process: After using the road map echarts, the timing modify other states, regardless of whether a former state and consistent, always will refresh the page, then the chart will be flashing, feeling very hard to accept, specifically looking for a solution, and record it:

react in a life-cycle approach: shouldComponentUpdate (nextProp, nextState), if this method returns false, then it will stop updating pages, respectively, than by the difference of the props and the state can determine whether you need to update the view, the following codes

import _ from 'lodash';
.
.
.
shouldComponentUpdate(nextProps,nextState){
    if(_.isEqual(nextProps.chart,this.props.chart)&&_.isEqual(nextState,this.state)){
        return false;
    }else{
        return true;
    }
}
// lodash是一个用于快捷操作对象、数组及其他类型数据的框架,里面封装了众多便利的方法,感兴趣的可以自行百度

These are the corresponding code, although relatively simple, but very useful, I hope to help you

Published 47 original articles · won praise 38 · views 60000 +

Guess you like

Origin blog.csdn.net/qq8241994/article/details/93753962