1座柱、當父組件的state改變后子組件也跟著從新渲染迷帜,顯然這不是我們要的效果。
解決方法:
子組件添加生命周期函數(shù) 判斷props和state狀態(tài)是否發(fā)生變化色洞,發(fā)生比變化后再從新渲染子組件戏锹。
shouldComponentUpdate(nextProps, nextState) {
? ? if (this.state.data !== nextState.data) {
? ? ? return true;
? ? }
? ? return false;
? }