This code fails, and the error says the `onClick` prop is not serializable. Why?

React JS interview question for Advanced practice.

Answer

ParentRSC is passing a regular function (handleClick) as a prop. Only Server Actions (defined with "use server") can be passed as function props.

Explanation

React Server Components cannot pass regular functions to Client Components because functions are not serializable and cannot be sent over the network. The only exception is for functions marked as Server Actions ("use server"), which are specifically designed to be callable from the client.

Related Questions