Performance: Immutable patterns for updates
MEDIUM IMPACT
This affects how efficiently the UI updates by minimizing unnecessary DOM changes and re-renders.
let items = [1, 2, 3]; function addItem(newItem) { items = [...items, newItem]; }
let items = [1, 2, 3]; function addItem(newItem) { items.push(newItem); items = items; // reassign to trigger update }
| Pattern | DOM Operations | Reflows | Paint Cost | Verdict |
|---|---|---|---|---|
| Mutable update with reassignment | Full list re-render | Multiple reflows | High paint cost | [X] Bad |
| Immutable update with new array | Partial DOM update | Single reflow | Low paint cost | [OK] Good |