Performance: Using props in JSX
MEDIUM IMPACT
Using props in JSX affects how React components render and update, impacting interaction responsiveness and rendering speed.
function Parent() { const data = React.useMemo(() => ({ name: 'Alice' }), []); return <Child info={data} />; } function Child({ info }) { return <div>{info.name}</div>; }
function Parent() { const data = { name: 'Alice' }; return <Child info={{ ...data }} />; } function Child({ info }) { return <div>{info.name}</div>; }
| Pattern | DOM Operations | Reflows | Paint Cost | Verdict |
|---|---|---|---|---|
| Inline new object props | Multiple due to re-renders | Multiple reflows triggered | Higher paint cost due to frequent updates | [X] Bad |
| Memoized stable props | Minimal DOM updates | Single or minimal reflows | Lower paint cost with fewer updates | [OK] Good |