Client Components Can Import Server Components
You'll learn: How to pass server components as children (or props) to client components, keeping them safely on the server.
The Surprising Pattern
Here's the twist: you can mix server and client components—but not through direct imports. Instead, you use the children pattern.
A client component can't directly import a server component (that would pull server-only code into the browser). But it can receive a server component as a prop or children. The server component stays on the server; only the client wrapper goes to the browser.
How It Works
// ClientWrapper.jsx
'use client'
export function ClientWrapper({ children }) {
const [count, setCount] = useState(0)
return (
<div>
<button onClick={() => setCount(count + 1)}>
Clicks: {count}
</button>
{children} {/* Server component rendered here */}
</div>
)
}
// page.jsx (Server Component)
import { ClientWrapper } from './ClientWrapper'
import { ServerContent } from './ServerContent' // Server component
export default function Page() {
return (
<ClientWrapper>
<ServerContent /> {/* Stays on server! */}
</ClientWrapper>
)
}
The parent (server) composes them together. The server renders <ServerContent /> to its wire format, then the client component receives it as an opaque "slot" to display.
Why This Matters
This pattern lets you add interactivity (client wrappers) around heavy, data-fetching server components without sacrificing the server benefits. The client component doesn't "see" the server component's code—it just positions the output.
Key Takeaway: Client components can't import server components directly, but they can receive them as children or props—keeping server logic safely on the server while adding client-side interactivity around it.