1. 程式人生 > >效能優化及路由跳轉

效能優化及路由跳轉

import React,{ Component } from "react"

import React,{ PureComponent } from "react"

PureComponent和Component的區別就是:PureComponent底層實現了shouldComponentUpdate,

這就不需要我們自己手寫shouldComponentUpdate做效能優化了。

【注】PureComponent的使用前提是使用 immutable.js框架,如果不適用immutable.js框架可能會有坑;

connect方法和store做了連線,這會產生一個問題-(只要store做了改變,首頁的元件都會重新渲染,
也就是每個元件的render函式都會重新執行,這會影響效能)
export default connect(mapStateToProps,mapDispatchToProps)(Home);

 

shouldComponentUpdate(){

可以在這個生命週期函式裡判斷,只有跟這個元件相關的資料發生改變的時候,

才讓這個組建的render函式執行,否則就return false,不讓這個元件的render函式執行。

}