Performance: Rendering lists in React
MEDIUM IMPACT
This affects how fast the page renders and updates when showing multiple items, impacting user interaction smoothness and load speed.
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 updated) | Many (each update triggers layout) | High (repaints all items) | [X] Bad |
| Unique stable keys | Low (only changed items updated) | Few (minimal layout recalculations) | Low (paints only changed items) | [OK] Good |
| Render all large list | Very high (thousands of nodes) | Many (heavy layout) | Very high (large paint area) | [X] Bad |
| Virtualized list | Low (only visible nodes) | Few (small layout area) | Low (small paint area) | [OK] Good |