Course contentsShow
← React
Lesson 1548 of 2,39638. Server Components FundamentalsFree lesson

The Composition Rule: Server Can Import Client, Not Vice Versa

Why Server Components can render Client Components as children, but Client Components cannot directly import Server Components.

The Composition Rule: Server Can Import Client, Not Vice Versa

What you'll learn: Why the component hierarchy allows Server Components to render Client Components as children, but Client Components cannot directly import Server Components.

The Fundamental Asymmetry

React Server Components enforce a strict directional rule: Server Components can import and render Client Components, but Client Components cannot import Server Components. This isn't arbitrary—it's essential to the architecture.

When a Server Component imports a Client Component, React simply tells the client: "Render this interactive component here." The Server Component acts as an orchestrator, deciding where Client Components appear and what props they receive. The server sends instructions downstream.

But the reverse breaks down. If a Client Component could import a Server Component, it would mean browser JavaScript trying to execute server-only code—accessing databases, file systems, or secret keys. There's no runtime that can make that work.

Why Composition Still Works

Here's the elegant exception: Server Components can pass other Server Components as children or props to Client Components. The Client Component doesn't "see inside" those Server Components—it just renders them in slots.

// Server Component
import ClientWrapper from './ClientWrapper' // 'use client'
import ServerChild from './ServerChild' // Server Component

export default function Page() {
  return (
    <ClientWrapper>
      <ServerChild /> {/* Server Component as children */}
    </ClientWrapper>
  )
}

The ClientWrapper doesn't know ServerChild is a Server Component. It just renders {children}. The server resolves ServerChild first, sends the output, and the client treats it as inert content.

The Mental Model

Think of it like a factory assembly line: upstream (server) can hand work to downstream (client), but the finished product (client) can't reach back and modify the factory machines (server).

Key Takeaway: Server Components control the tree and can embed Client Components anywhere. Client Components cannot import Server Components directly, but can receive them as pre-rendered props or children—maintaining the unidirectional data flow from server to client.