匿名綁定對性能的影響-數聽說話

實驗

線上demo: https://codesandbox.io/s/4j3k...
首次進頁面render結果函數

clipboard.png

state 變化後的結果性能

clipboard.png

結果總結

組件 綁定方式 結果 (首次 render 次數) 不涉及當前組件組件父組件state變化後render次數
class組件 非箭頭函數函數 1次 1次
class組件 箭頭函數函數 1次 1次
pureclass組件 箭頭函數 1次 1次
pureclass組件 非箭頭函數 1次 0次

結論

非匿名函數 + pureComponent 組件能優化性能優化

原理

相關文章
相關標籤/搜索