Performance: Props as read-only data
MEDIUM IMPACT
This concept affects how React components update and render, impacting interaction responsiveness and rendering speed.
function Child({ data }) { const newValue = 10; // Use local state or variables instead return <div>{newValue}</div>; } function Parent() { const info = { value: 5 }; return <Child data={info} />; }
function Child({ data }) { data.value = 10; // Mutating props directly return <div>{data.value}</div>; } function Parent() { const info = { value: 5 }; return <Child data={info} />; }
| Pattern | DOM Operations | Reflows | Paint Cost | Verdict |
|---|---|---|---|---|
| Mutating props inside child | Causes extra DOM updates | Multiple reflows if state changes triggered | Higher paint cost due to unnecessary updates | [X] Bad |
| Treating props as read-only | Minimal DOM updates | Single reflow when needed | Lower paint cost with optimized rendering | [OK] Good |