Question presented to candidate: "In the App Router, what is the difference between a Server Component and a Client Component, how do you decide which to use, and how do they work together?"
What a strong answer should cover:
- Server Components are the default in app/: they run only on the server, can be async, can read databases and secrets, and send no JavaScript to the browser.
- Client Components start at a
'use client'file: they are server-rendered to HTML and then hydrated, so they can use state, effects, event handlers and browser APIs. - A Client Component cannot import a Server Component, but can receive one as children or props.
- Props from server to client must be serializable (functions and class instances are rejected).
- Guideline: keep data and static UI on the server, push
'use client'down to small interactive leaves.
Clarifying questions expected:
- "Which parts need interactivity or browser APIs?" β only those need to be Client Components.
- "Does anything touch secrets or the database?" β keep it on the server with server-only.
Code / implementation expected: Yes β a server page composing a client leaf.