Performance: Component organization
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 |
Button?function Greeting({ name }) {
return <h1>Hello, {name}!</h1>;
}
function App() {
return <Greeting name="Alice" />;
}function Header() {
return <header>Welcome</header>;
}
function App() {
return (
<div>
<Header />
<Footer />
</div>
);
}Dashboard component that uses smaller components like Sidebar, Content, and Footer. Which approach best follows good component organization?Pass the test and this pattern moves unknown