Performance: Why React is used
MEDIUM IMPACT
React affects page load speed and interaction responsiveness by managing UI updates efficiently.
import { useState } from 'react'; function Counter() { const [count, setCount] = useState(0); const increment = () => setCount(c => c + 1); return <button onClick={increment}>Count: {count}</button>; }
const updateUI = () => { const element = document.getElementById('count'); element.innerText = newCount; }; // Called multiple times rapidly updateUI(); updateUI(); updateUI();
| Pattern | DOM Operations | Reflows | Paint Cost | Verdict |
|---|---|---|---|---|
| Direct DOM manipulation on every change | Many direct node updates | Multiple reflows per update | High paint cost due to frequent changes | [X] Bad |
| React state updates with virtual DOM | Minimal DOM updates after diffing | Single reflow per batch | Lower paint cost due to optimized updates | [OK] Good |