Performance: Functional components
This affects initial page load speed and interaction responsiveness by how React renders and updates UI components.
function Button({ label }) { return <button>{label}</button>; }
class Button extends React.Component { render() { return <button>{this.props.label}</button>; } }
| Pattern | DOM Operations | Reflows | Paint Cost | Verdict |
|---|---|---|---|---|
| Class component with instance | More nodes due to lifecycle wrappers | Multiple reflows if state changes trigger full re-renders | Higher paint cost due to extra DOM updates | [X] Bad |
| Functional component with hooks | Minimal nodes, direct function calls | Single reflow per state change | Lower paint cost due to optimized updates | [OK] Good |
Greeting?function Welcome(props) {
return <h2>Hello, {props.name}!</h2>;
}
// Usage: <Welcome name="Alice" />function Counter() {
const [count, setCount] = useState(0);
return (
<div>
<p>Count: {count}</p>
<button onClick={() => setCount(count + 1)}>Increment</button>
</div>
);
}Pass the test and this pattern moves unknown