Performance: Passing props to components
MEDIUM IMPACT
Passing props affects rendering speed and update efficiency of React components.
function Parent() { const name = 'Alice'; return <Child name={name} />; } function Child({name}) { return <div>{name}</div>; }
function Parent() { const data = {name: 'Alice', age: 30, city: 'NYC'}; return <Child {...data} />; } function Child(props) { return <div>{props.name}</div>; }
| Pattern | DOM Operations | Reflows | Paint Cost | Verdict |
|---|---|---|---|---|
| Passing all props indiscriminately | Same DOM nodes reused | Multiple re-renders triggered | Paint cost depends on re-rendered nodes | [X] Bad |
| Passing only necessary props | Same DOM nodes reused | Minimal re-renders | Lower paint cost due to fewer updates | [OK] Good |