Performance: Ternary operator usage
MEDIUM IMPACT
This affects rendering speed by controlling conditional rendering efficiently without extra DOM nodes or unnecessary re-renders.
function Component({ isLoggedIn }) { return <div>{isLoggedIn ? 'Welcome back!' : 'Please log in.'}</div>; }
function Component({ isLoggedIn }) { if (isLoggedIn) { return <div>Welcome back!</div>; } else { return <div>Please log in.</div>; } }
| Pattern | DOM Operations | Reflows | Paint Cost | Verdict |
|---|---|---|---|---|
| If-else with multiple returns | Multiple React reconciliation checks | Potential multiple reflows if DOM changes | Higher paint cost due to extra DOM updates | [!] OK |
| Ternary operator inline | Single reconciliation check | Single reflow if DOM changes | Lower paint cost with minimal DOM updates | [OK] Good |