What data types and values can be safely passed as props from a server component to a client component?
Short answer
You can pass any value that can be serialized, such as strings, numbers, plain objects, and arrays, but you cannot pass things like functions, class instances, or database connection objects, since these cannot be sent across the boundary from server rendered code into the…
Advertisement
AModel answer
You can pass any value that can be serialized, such as strings, numbers, plain objects, and arrays, but you cannot pass things like functions, class instances, or database connection objects, since these cannot be sent across the boundary from server rendered code into the browser's JavaScript environment.
// Safe to pass: serializable data
<ClientComponent title={post.title} tags={post.tags} />
// Not safe to pass: a function or a database client
// <ClientComponent onSave={saveToDatabase} /> // this will not workReal-world example
A team accidentally tries passing a database query function as a prop into a client component, gets an error, and instead refactors to call that function inside the server component and pass only the resulting plain data down.
Likely follow-ups
- What happens if you try to pass a non-serializable value as a prop?
- Are there exceptions that allow passing certain function-like values, such as server actions?
Related topics