Performance: Component organization
MEDIUM IMPACT
This affects the rendering speed and responsiveness by controlling how React updates and re-renders components.
function StaticText() { return <p>Some static text that never changes</p>; } function Counter({ count, onIncrement }) { return ( <> <h1>Counter: {count}</h1> <button onClick={onIncrement}>Increment</button> </> ); } function App() { const [count, setCount] = React.useState(0); return ( <div> <Counter count={count} onIncrement={() => setCount(count + 1)} /> <StaticText /> </div> ); }
function App() { const [count, setCount] = React.useState(0); return ( <div> <h1>Counter: {count}</h1> <button onClick={() => setCount(count + 1)}>Increment</button> <p>Some static text that never changes</p> </div> ); }
| Pattern | DOM Operations | Reflows | Paint Cost | Verdict |
|---|---|---|---|---|
| Single large component | Many nodes updated on state change | Multiple reflows per update | High paint cost due to full re-render | [X] Bad |
| Small focused components | Only changed components update DOM | Single or minimal reflows | Lower paint cost, faster updates | [OK] Good |