問題:動畫組件,性能落后
相同組件過多,頁面顯示令人尷尬的動畫效果
常見的陷阱
- 不好的shouldComponentUpdate實(shí)現(xiàn),為什么PureComponent也不能解決問題
- 太過頻繁的更改dom
- 沒有限制使用事件和回調(diào)
class ShouldNotUpdate extends React.Component {
constructor(props){
super(props)
}
shouldComponentUpdate(nextProps, nextState){
return this.props.children !== nextProps.children
}
render(){
return `I should be rendered only 1 time. actual times renderd : {++this.counter}`
}
}