Performance: Handling input fields
MEDIUM IMPACT
This affects interaction responsiveness and rendering speed when users type or change input values.
function Input() { const [value, setValue] = React.useState(''); const handleChange = React.useCallback(e => setValue(e.target.value), [setValue]); return <input value={value} onChange={handleChange} />; }
function Input() { const [value, setValue] = React.useState(''); return <input value={value} onChange={e => setValue(e.target.value)} />; }
| Pattern | DOM Operations | Reflows | Paint Cost | Verdict |
|---|---|---|---|---|
| Controlled input with state update on every keystroke | Many updates | 1 per keystroke | High due to frequent layout | [X] Bad |
| Controlled input with memoized handlers and calculations | Many updates | 1 per keystroke | Medium due to optimized JS | [!] OK |
| Uncontrolled input with ref and no state updates | Minimal updates | 0 during typing | Low paint cost | [OK] Good |