Course contentsShow
← React
Lesson 1593 of 2,39639. Server Components in PracticeFree lesson

Dates Serialize as Strings

Date objects crossing the boundary become ISO strings; you must reconstruct them on the client side.

Dates Serialize as Strings

What you'll learn: Why Date objects turn into ISO strings when passed from Server to Client Components, and how to handle them correctly.

The Serialization Surprise

When a Server Component passes a Date object as a prop to a Client Component, React doesn't (and can't) send the actual JavaScript Date object across the network. Instead, it automatically serializes the Date into an ISO 8601 string format like "2024-01-15T10:30:00.000Z".

This happens because of the serialization boundary you learned about earlier—only JSON-compatible data can cross from server to client. Date objects aren't part of the JSON specification, so React converts them to strings.

What This Looks Like

On the server, you might fetch data like this:

// Server Component
async function EventList() {
  const events = await fetchEvents(); // Returns { name: "Party", date: new Date(...) }
  return <EventCard event={events[0]} />;
}

But in your Client Component, event.date arrives as a string, not a Date object:

'use client';

function EventCard({ event }) {
  // event.date is "2024-01-15T10:30:00.000Z", NOT a Date object
  // This won't work: event.date.getMonth()
  
  const actualDate = new Date(event.date); // Reconstruct it
  const formatted = actualDate.toLocaleDateString();
  
  return <div>{formatted}</div>;
}

Think of It Like Shipping

Imagine shipping a live plant (Date object) across the country. You can't send the living plant itself—you send seeds (ISO string) that the recipient can use to grow their own plant (reconstruct the Date).

Key Takeaway: Date objects automatically become ISO strings when crossing the server-client boundary. Always reconstruct them with new Date(stringValue) in your Client Components before using Date methods.