Performance: Why server components are the default
This affects the initial page load speed and reduces client-side JavaScript execution, improving user experience.
export default async function Page() { const data = await fetchData(); return <div>Data: {data.value}</div>; }
'use client' import React from 'react'; export default function Page() { const [count, setCount] = React.useState(0); return <button onClick={() => setCount(count + 1)}>Count: {count}</button>; }
| Pattern | DOM Operations | Reflows | Paint Cost | Verdict |
|---|---|---|---|---|
| Client Components by default | More DOM nodes from hydration | Multiple reflows during hydration | Higher paint cost due to JS execution | [X] Bad |
| Server Components by default | Minimal DOM nodes, static HTML | Single reflow on initial load | Lower paint cost, faster display | [OK] Good |
use client at the very top of the file.use client at the top of the file. -> Option Cexport default function Page() {
return (
<div>Hello from server component</div>
)
}export default function Button() {
const [count, setCount] = React.useState(0);
return <button onClick={() => setCount(count + 1)}>Clicked {count} times</button>;
}use client directive, so state and events won't work. -> Option DPass the test and this pattern moves unknown