react组件性能优化PureComponent

首先我们使用react组件会配合connect来连接store获取state,那么只要store中的state发生改变组件就会重新渲染,所以性能不高,一般我们可以使用shouldComponentUpdate()来判断,但react提供了PureComponent组件,当我们把Component替换成PureComponent的时候会自动帮我们优化组件避免不必要的渲染,注意:前提是使用immutable来管理数据,不然会出现一些问题。

1
2
3
4
5
6
7
import React, { PureComponent } from 'react';
class App extends PureComponent{
render(){
return(<div></div>);
}
}
export default App;
#

评论

Your browser is out-of-date!

Update your browser to view this website correctly. Update my browser now

×