It is to my knowledge that if a parent component rerenders, then all its children will rerender UNLESS they implement shouldComponentUpdate()
. I made an example where this doesn't seem to be the true.
I have 3 components: <DynamicParent/>
, <StaticParent/>
and <Child/>
. The <Parent/>
components are responsible for rendering the <Child/>
but do so in different ways.
<StaticParent/>
's render function statically declares the <Child/>
before runtime, like so:
<StaticParent>
<Child />
</StaticParent>
While the <DynamicParent/>
handles receiving and rendering the <Child/>
dynamically at runtime, like so:
<DynamicParent>
{ this.props.children }
</DynamicParent>
Both <DynamicParent/>
and <StaticParent/>
have onClick
listeners to change their state and rerender when clicked. I noticed that when clicking <StaticParent/>
both it and the <Child/>
are rerendered. But when I click <DynamicParent/>
, then only the parent and NOT <Child/>
are rerendered.
<Child/>
is a functional component without shouldComponentUpdate()
so I don't understand why it doesn't rerender. Can someone explain why this is to be the case? I can't find anything in the docs related to this use case.