Server Component vs Client Component?
Try code in the playgroundUnderstand the concept
A Server Component runs in the server environment and does not ship its component implementation to the browser as interactive JavaScript. A Client Component is part of a client boundary and supports state, effects and browser events. In Next.js, Client Components can still contribute server-generated HTML on the initial load, so client does not mean browser-only rendering.
Important ideas
- Server Components can fetch server data without shipping their component code to the browser.
- Client Components support state, effects and browser events through a
'use client'boundary. - Client Components can still be pre-rendered on the server for the initial page.
Reference: Next.js server and client components.
- Keep sensitive data access server-side and pass only serializable, necessary data across the boundary.
Can you explain it without the notes?
Server Component vs Client Component?
Use your own words. Explain an example and one limitation before checking the explanation.
Check your explanation
A Server Component runs in the server environment and does not ship its component implementation to the browser as interactive JavaScript. A Client Component is part of a client boundary and supports state, effects and browser events. In Next.js, Client Components can still contribute server-generated HTML on the initial load, so client does not mean browser-only rendering.
Turn this concept into a clear answer.
- Use a small interactive client subtree inside a server-rendered page instead of making the entire page a client component without a reason.
Adapted from 06_REACT_NEXTJS.md · “Server Component vs Client Component?”. Examples are study fragments; framework behavior can depend on your version.