Performance: Component composition
MEDIUM IMPACT
Component composition affects rendering speed and responsiveness by how components are structured and reused in React apps.
const MemoizedChild = React.memo(function Child() { return <div>Static content</div>; }); function Parent() { return <div>{Array(100).fill(null).map(() => <MemoizedChild />)}</div>; }
function Parent() { return <div>{Array(100).fill(null).map(() => <Child />)}</div>; } function Child() { return <div>{Math.random()}</div>; }
| Pattern | DOM Operations | Reflows | Paint Cost | Verdict |
|---|---|---|---|---|
| Unmemoized nested components with changing props | High (many re-renders) | High (many layout recalculations) | High (many paints) | [X] Bad |
| Memoized components with stable props | Low (minimal re-renders) | Low (few layout recalculations) | Low (few paints) | [OK] Good |