Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Does shouldComponentUpdate prevent connected children from updating

Tags:

reactjs

redux

Say I have a component that renders children but those children can be redux connected or timer based updating components. The parent component does not know that. Yet, the parent component implements shouldComponentUpdate for performance optimizations.

class Container extends React.Component {
  shouldComponentUpdate(nextProps, nextState) { return shallowCompare(this, nextProps, nextState) } 

  render() {
     return <div>
       <h1>{this.props.title}</h1>
       { children }
     </div>
  }
}

Lets say, Clock is a self updating/connected component. And in this constellation:

<Container title="Current Time">
  <Clock/>
</Container>

would Clock still be updated when its properties change due to redux state changes or an internal timeout (however it its implemented) despite its parent component title never changes and therefore the componentShouldUpdate call returns false?

like image 527
philk Avatar asked Dec 25 '22 01:12

philk


1 Answers

If Clock is receiving props from Container, and Container does not update because of shouldComponentUpdate, then Clock will not update. If it is connected to the store, then it should update because it will receive props directly.

like image 104
Benjamin Avatar answered Apr 30 '23 04:04

Benjamin