Pass server data to client components as props
Load data in a Next.js 16 Server Component and hand it to a Client Component as serializable props, instead of fetching it again in the browser.
A Client Component that needs data can fetch it in an effect, which costs a second round trip. It is better to load it on the server and pass it in.
import { CartList } from './CartList';
import { getCart } from '@/lib/cart';
export default async function CartPage() {
const items = await getCart();
return <CartList initialItems={items} />;
}'use client';
import { useState } from 'react';
export function CartList({ initialItems }) {
const [items, setItems] = useState(initialItems);
return (
<ul>
{items.map((item) => (
<li key={item.id}>
{item.name}
<button onClick={() => setItems(items.filter((i) => i.id !== item.id))}>
Remove
</button>
</li>
))}
</ul>
);
}Pen [Remove]
Ink [Remove] (in the first HTML response, before any client fetch)The server renders the list with real data, so the visitor sees it at once, and the client takes over for the interactive part, seeded through initialItems. Props crossing the boundary must be serializable: strings, numbers, plain objects and arrays, Date, Map, Set and promises. Functions and class instances are not allowed, except Server Functions. See Passing props from Server to Client Components.
Never pass secrets, such as a full user record with a password hash, because everything in the props ends up in the page payload.