Performance: Keys concept
HIGH IMPACT
This concept affects how React updates the UI efficiently by identifying which items changed, added, or removed in lists.
const listItems = items.map(item => <li key={item.id}>{item.name}</li>);const listItems = items.map((item, index) => <li key={index}>{item.name}</li>);| Pattern | DOM Operations | Reflows | Paint Cost | Verdict |
|---|---|---|---|---|
| Index as key | Many unnecessary node replacements | Multiple reflows on reorder | High paint cost due to full updates | [X] Bad |
| Unique stable key | Minimal DOM changes | Single reflow per actual change | Low paint cost with targeted updates | [OK] Good |