Performance: Parent-child data flow
MEDIUM IMPACT
This concept affects how efficiently data updates propagate through components, impacting interaction responsiveness and rendering speed.
function Parent() { const [count, setCount] = React.useState(0); const data = React.useMemo(() => ({ count }), [count]); return <Child data={data} />; } function Child({ data }) { console.log('Child rendered'); return <div>{data.count}</div>; }
function Parent() { const [count, setCount] = React.useState(0); return <Child data={{ count, timestamp: Date.now() }} />; } function Child({ data }) { console.log('Child rendered'); return <div>{data.count}</div>; }
| Pattern | DOM Operations | Reflows | Paint Cost | Verdict |
|---|---|---|---|---|
| Passing new object literals as props | Child re-renders every parent update | Triggers reflow per child render | Paints child content each time | [X] Bad |
| Memoizing props with useMemo | Child re-renders only on data change | Single reflow per actual update | Paints only changed content | [OK] Good |