Performance: Conditional component rendering
MEDIUM IMPACT
This affects how quickly the page shows relevant content and how much work the browser does updating the UI.
function MyComponent({ show }) { return ( <div> {show ? <ComponentC /> : <ComponentA />} </div> ); }
function MyComponent({ show }) { return ( <div> <ComponentA /> <ComponentB /> {show ? <ComponentC /> : null} </div> ); }
| Pattern | DOM Operations | Reflows | Paint Cost | Verdict |
|---|---|---|---|---|
| Render all components regardless of condition | High (many nodes) | Multiple reflows | High paint cost | [X] Bad |
| Render components conditionally based on need | Low (minimal nodes) | Single reflow | Low paint cost | [OK] Good |