react性能优化

2017-06-01  本文已影响0人  呱呱呱_____

性能检测工具

安装react性能检测工具:

npm i react-addons-perf --save-dev

然后在./app/index.js中加入参数:

import Perf from 'react-addons-perf' 
if (__DEV__) { window.Perf = Perf }

优化方法

推荐使用官方的优化方法:
优化shouldComponentUpdate,使用官网的优化插件 react-addons-pure-render-mixin

安装:npm i -save react-addons-pure-render-mixin;
使用:

import PureRenderMixin from 'react-addons-pure-render-mixin';
class XXX extends Compoennt{
    constructor(props, context){
        super(props, context);
        this.shouldComponentUpdate = PureRenderMixin.shouldComponentUpdate;
    }
    ....
}

每个组件都可以这样写。

上一篇 下一篇

猜你喜欢

热点阅读