Performance: Controlled components
MEDIUM IMPACT
This concept affects input responsiveness and rendering speed during user interactions.
function Form() { const [value, setValue] = React.useState(''); const handleChange = React.useCallback(e => setValue(e.target.value), [setValue]); return <input value={value} onChange={handleChange} />; }
function Form() { const [value, setValue] = React.useState(''); return <input value={value} onChange={e => setValue(e.target.value)} />; }
| Pattern | DOM Operations | Reflows | Paint Cost | Verdict |
|---|---|---|---|---|
| Unmemoized onChange handler | 1 input node updated per keystroke | 1 reflow per keystroke | Low to medium paint cost | [X] Bad |
| Memoized onChange handler with useCallback | 1 input node updated per keystroke | 1 reflow per keystroke | Low paint cost | [OK] Good |