Performance: Passing arguments to handlers
MEDIUM IMPACT
This affects interaction responsiveness and rendering speed when event handlers receive arguments.
function MyButton() { const handleClickWithArg = React.useCallback(() => handleClick('arg'), []); return <button onClick={handleClickWithArg}>Click me</button>; } function handleClick(value) { console.log(value); }
function MyButton() { return <button onClick={() => handleClick('arg')}>Click me</button>; } function handleClick(value) { console.log(value); }
| Pattern | DOM Operations | Reflows | Paint Cost | Verdict |
|---|---|---|---|---|
| Inline arrow function in JSX | No direct DOM ops, but triggers React reconciliation | 0 | Low paint cost but extra React work | [X] Bad |
| Memoized handler with useCallback | No extra DOM ops, stable React props | 0 | Minimal paint cost, efficient React updates | [OK] Good |