Performance: Inline vs function handlers
MEDIUM IMPACT
This affects interaction responsiveness and rendering performance by controlling how event handlers are created and reused in React components.
import { useCallback } from 'react'; function MyButton() { const handleClick = 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 function handler | No extra DOM ops | Causes extra React re-renders | No direct paint cost | [X] Bad |
| Stable function handler reference | No extra DOM ops | Minimal React re-renders | No direct paint cost | [OK] Good |