幾週前 React 發佈了版本 16.6,一口氣推出了 lazy
、memo
及 contextType
等新功能。而其中的 React.memo
就是過去 React.PureComponent
的 HOC 版本,比起過去改動成 PureComponent 要動到較大量的程式碼,如今只要套上 React.memo
即可。不過在 class component 可以寫 class method 自定 shouldComponentUpdate
的實作,function component 好像不能這樣搞?其實 memo 是有第二個參數可以使用的。