React Server Components vs. Client Components
Next.js App Router components are React Server Components (RSC) by default. RSCs can execute direct database queries, access secure environment variables, and stream rendered chunks to the client using React Suspense. Because RSC code stays on the server, large npm libraries used inside them add 0 bytes to the client JavaScript bundle.
When a component requires interactivity — browser event listeners (onClick), React state hooks (useState), or browser APIs (window, localStorage) — you mark it as a Client Component by placing the 'use client' directive at the very top of the file. A best practice is to push 'use client' directives down the component tree, keeping parent containers as Server Components.
Exercise
Refactor an interactive form card into a Server Component container with a separate Client Component toggle button for handling user clicks.
Check your understanding
Can a Server Component import a Client Component?Show answerHide answer
Answer
Yes — Server Components can render Client Components as children and pass serializable props to them.What happens if you try to use useState inside a component without 'use client'?Show answerHide answer
Answer
Next.js compilation fails with a build error stating hooks can only be used in Client Components.