Performance: Handling events in React
MEDIUM IMPACT
This affects how quickly the app responds to user actions and how efficiently the browser updates the UI after events.
function MyButton() { const handleClick = React.useCallback(() => { console.log('Clicked'); }, []); return <button onClick={handleClick}>Click me</button>; }
function MyButton() { return <button onClick={() => console.log('Clicked')}>Click me</button>; }
| Pattern | DOM Operations | Reflows | Paint Cost | Verdict |
|---|---|---|---|---|
| Inline arrow function in JSX | Multiple event handler re-registrations | Multiple reflows if state changes unnecessarily | Higher paint cost due to frequent updates | [X] Bad |
| Memoized handler with useCallback | Single event handler registration | Minimal reflows only when needed | Lower paint cost due to fewer updates | [OK] Good |