Performance: Lifecycle mapping with hooks
MEDIUM IMPACT
This concept affects how React components manage rendering and updates, impacting interaction responsiveness and rendering speed.
function MyComponent() { React.useEffect(() => { console.log('Effect runs once on mount'); }, []); return <div>Hello</div>; }
function MyComponent() { React.useEffect(() => { // expensive operation console.log('Effect runs every render'); }); return <div>Hello</div>; }
| Pattern | DOM Operations | Reflows | Paint Cost | Verdict |
|---|---|---|---|---|
| Effect without dependencies | N/A | Multiple reflows per render | High paint cost due to repeated updates | [X] Bad |
| Effect with empty dependency array | N/A | Single reflow on mount | Minimal paint cost | [OK] Good |
| State update inside effect without dependencies | N/A | Infinite reflows | Continuous paint blocking UI | [X] Bad |
| Multiple separate effects | N/A | Multiple reflows | Moderate paint cost | [!] OK |
| Combined effects in one hook | N/A | Single reflow | Lower paint cost | [OK] Good |