Undefined vs Null in Serialization
What you'll learn: Why undefined disappears when passing data from Server to Client Components, and when you need to use null instead.
When React serializes props to cross the server-client boundary, undefined and null behave very differently. Understanding this distinction prevents subtle bugs in Server Components.
The Core Difference
In JavaScript object serialization (like JSON), undefined values are omitted entirely, while null values are preserved. This matters when passing props from Server Components to Client Components.
// Server Component
<ClientComponent
name={undefined} // This prop won't exist at all
age={null} // This prop will be null
/>
In the Client Component, checking these values reveals the difference:
'use client'
export default function ClientComponent({ name, age }) {
console.log('name' in props); // false - property doesn't exist
console.log(name); // undefined (but missing from object)
console.log('age' in props); // true - property exists
console.log(age); // null
}
When It Matters
This distinction becomes critical when you need to differentiate between "not provided" and "explicitly empty":
// Server Component fetching user data
const user = await db.getUser(id);
<UserProfile
bio={user.bio ?? null} // Use null, not undefined
avatar={user.avatar ?? null}
/>
Without converting undefined to null, you lose the ability to tell whether bio was absent from the database or simply not included in the props.
The Analogy
Think of undefined like leaving a form field blank—it's not submitted at all. null is like writing "N/A"—you're explicitly stating there's no value.
Key Takeaway: When serializing props across the server-client boundary, undefined values vanish completely while null values are preserved. If the distinction between "absent" and "empty" matters, always use null explicitly.