Server vs Client Components
Components are Server Components by default. Opt in to the client only where you need interactivity.
- Server Components can be async, read data directly, and ship zero JS for themselves.
- Add 'use client' at the top of a file for state, effects, event handlers and browser APIs.
- Server Components can render Client Components and pass them serialisable props (or other server-rendered children).
- import 'server-only' guarantees a module never leaks into a client bundle.
See it in this app: src/components/task-list.tsx (client) fed by src/app/(app)/projects/[id]/page.tsx (server)
// Server Component fetches, Client Component interacts
export default async function Page() {
const tasks = await listTasks("p1");
return <TaskList tasks={tasks} />; // TaskList is "use client"
}