Performance: Synthetic events
MEDIUM IMPACT
Synthetic events affect how user interactions are handled and can impact input responsiveness and event processing speed.
function Button() { return <button onClick={() => console.log('Clicked')}>Click me</button>; }
function Button() { return <button onClick={(e) => { e.persist(); console.log('Clicked'); }}>Click me</button>; }
| Pattern | DOM Operations | Reflows | Paint Cost | Verdict |
|---|---|---|---|---|
| Using React synthetic events normally | No extra DOM ops | 0 | 0 | [OK] Good |
| Calling e.persist() on synthetic events | No extra DOM ops | 0 | 0 | [!] OK - higher memory use |
| Using native DOM events directly in React | No extra DOM ops | 0 | 0 | [!] OK - bypasses React pooling |
| Heavy event handler logic inside synthetic events | No extra DOM ops | 0 | 0 | [X] Bad - slows input responsiveness |