Performance: Updating phase
HIGH IMPACT
This affects how quickly React updates the UI after state or props change, impacting interaction responsiveness and visual stability.
function Search() { const [query, setQuery] = React.useState(''); const [debouncedQuery, setDebouncedQuery] = React.useState(''); React.useEffect(() => { const handler = setTimeout(() => setDebouncedQuery(query), 300); return () => clearTimeout(handler); }, [query]); function handleChange(e) { setQuery(e.target.value); } return <input value={query} onChange={handleChange} />; }
function Search() { const [query, setQuery] = React.useState(''); function handleChange(e) { setQuery(e.target.value); } return <input value={query} onChange={handleChange} />; }
| Pattern | DOM Operations | Reflows | Paint Cost | Verdict |
|---|---|---|---|---|
| Frequent state updates on every input | Many small DOM updates | Many reflows per keystroke | High paint cost due to frequent changes | [X] Bad |
| Debounced state updates | Fewer DOM updates | Single reflow per debounce interval | Lower paint cost | [OK] Good |
| No memoization on large lists | All child nodes updated | Many reflows | High paint cost | [X] Bad |
| Memoized child components | Minimal DOM updates | Few reflows | Low paint cost | [OK] Good |