Common Next.js errorsFunctions cannot be passed directly to Client Components
Error: Functions cannot be passed directly to Client Components unless you explicitly expose it by marking it with "use server". A Server Component handed a function, usually an event handler like onClick or a formatter, to a Client Component as a prop.
Why it happens
Props that cross from server to client are sent as data, so they must be serialisable: strings, numbers, plain objects, arrays, dates, promises. A function can't be turned into data, so React refuses it. The same applies to class instances.
How to fix it
Move the function into the Client Component, and pass only the data it needs:
// Before: app/page.tsx (Server Component)
<LikeButton onLike={() => console.log('liked')} />
// After: app/like-button.tsx
'use client'
export function LikeButton({ postId }: { postId: string }) {
return <button onClick={() => like(postId)}>Like</button>
}
// app/page.tsx
<LikeButton postId={post.id} />
If the function has to run on the server (saving to the database, say), make it a Server Function with 'use server'. That crosses the boundary as a reference the client can call, not as code.