Interleaving server and client
You will often want a Client Component — say an interactive tabs or search widget — to render server-fetched content. But you cannot import a Server Component into a Client Component: the import drags the child across the boundary and it becomes a Client Component too.
The answer is composition. Pass the Server Component into the Client
Component as a prop, most commonly children:
// app/dashboard/page.tsx — a Server Component
import { Tabs } from './tabs'; // a Client Component
export default async function Page() {
const data = await getData();
return (
<Tabs>
<ServerChart data={data} />
</Tabs>
);
}
Tabs is a Client Component that renders {children}. ServerChart is written
in the parent — a Server Component — so it is rendered on the server and passed
in as already-rendered content. Tabs wraps interactive chrome around it
without ever owning the server code.
This is the general rule: Server Components can render Client Components, and a Server Component can pass another Server Component to a Client Component through props. The child keeps its server identity because the parent that created it is a Server Component. Props crossing the boundary must still be serializable, which is the next Lesson.
You are about to answer a short quiz on composition via children.