Consider the two different render method of Parent Component, P :
render() {
return
<ChildComponent propA={ { staticKey: staticValue} }/>
}
render() {
return someStaticData.map( data =>
<ChildComponent>
<span>
{
data.value.map(dataInner =>
<span>
{ dataInner.value }
<span>
)}
</span>
</ChildComponent>
)
}
Child component handles shouldComponentUpdate
as recommended by React Guide.
shouldComponentUpdate(nextProps, nextState) {
return shallowCompare(this, nextProps, nextState);
}
In both the above expample cases shallowCompare
of child component always returns true, even if the object / child I'm passing is exactly the same (because the references changed). This is causing a lot of wasted renders.
How does one pass a static object / child as props without breaking SCU?
Maybe switching to an immutable data structure would help since then the SCU hook will only need to compare reference inequalities:
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.