Performance: useState hook introduction
MEDIUM IMPACT
This affects interaction responsiveness and rendering speed when updating component state.
const [count, setCount] = useState(0); function handleClick() { setCount(prev => prev + 2); }
const [count, setCount] = useState(0); function handleClick() { setTimeout(() => { setCount(count + 1); }, 0); setTimeout(() => { setCount(count + 2); }, 0); }
| Pattern | DOM Operations | Reflows | Paint Cost | Verdict |
|---|---|---|---|---|
| Multiple setState calls separately | Multiple updates | Multiple reflows | Multiple paints | [X] Bad |
| Single functional setState call | Single update | Single reflow | Single paint | [OK] Good |