假设我有一个渲染的组件,children但这些子组件可以redux连接或基于计时器更新组件.父组件不知道这一点.然而,父组件实现shouldComponentUpdate了性能优化.
class Container extends React.Component {
shouldComponentUpdate(nextProps, nextState) { return shallowCompare(this, nextProps, nextState) }
render() {
return <div>
<h1>{this.props.title}</h1>
{ children }
</div>
}
}
Run Code Online (Sandbox Code Playgroud)
可以说,Clock是一个自我更新/连接的组件.而在这个星座:
<Container title="Current Time">
<Clock/>
</Container>
Run Code Online (Sandbox Code Playgroud)
就Clock当它的属性变化,由于仍然可以更新redux状态变化或内部超时(但它的实现),尽管它的父组件title从未改变,因此componentShouldUpdate调用返回false?
如果Clock是接收道具Container,并且Container因为没有更新shouldComponentUpdate,则Clock不会更新.如果它连接到商店,那么它应该更新,因为它将直接接收道具.
| 归档时间: |
|
| 查看次数: |
2846 次 |
| 最近记录: |