Performance: What is state
MEDIUM IMPACT
State affects how React components update and re-render, impacting interaction responsiveness and rendering speed.
const [count, setCount] = useState(0); function increment() { setCount(prev => prev + 3); }
const [count, setCount] = useState(0); function increment() { setCount(count + 1); setTimeout(() => setCount(count + 2), 0); }
| Pattern | DOM Operations | Reflows | Paint Cost | Verdict |
|---|---|---|---|---|
| Multiple separate state updates | Multiple DOM updates | Multiple reflows | Higher paint cost | [X] Bad |
| Single batched state update | Minimal DOM updates | Single reflow | Lower paint cost | [OK] Good |