Performance: Common list rendering mistakes
HIGH IMPACT
This affects rendering speed and user interaction responsiveness when displaying lists in React.
const List = ({ items }) => items.map(item => <li key={item.id}>{item.name}</li>);const List = ({ items }) => items.map((item, index) => <li key={index}>{item}</li>);| Pattern | DOM Operations | Reflows | Paint Cost | Verdict |
|---|---|---|---|---|
| Index as key | High (all items re-render) | Many (on any change) | High (full list repaint) | [X] Bad |
| Stable unique keys | Low (only changed items) | Few (minimal) | Low (partial repaint) | [OK] Good |
| Rendering full large list | Very high (thousands of nodes) | Many (heavy layout) | Very high (full repaint) | [X] Bad |
| Virtualized list | Low (only visible nodes) | Few (small layout) | Low (small repaint) | [OK] Good |
| Inline functions in render | Causes extra re-renders | Extra reflows due to re-renders | Increased paint cost | [X] Bad |
| Memoized callbacks | Stable renders | Minimal reflows | Reduced paint cost | [OK] Good |