父組件每次改變state,都會觸發render,然后觸發子組件,如果不用觸發子組件可以用
shouldComponentUpdate聲明周期控制
在子組件里放入:
shouldComponentUpdate(nextPros) {
console.log('是否更新了');
if (nextPros.name== this.props.name) {
return false; //如果當前props的值和傳過來的值一樣就不用觸發更新
}
return true;
}