Pages

Topics

Tools

↑↓navigate↵openescclose
All guides

Next.js: Functions cannot be passed to Client Components

A function prop cannot cross into a Client Component unless it is a server action. Move the handler, mark it use server, or pass data instead.

~4 min readNext.js
#Next.js#App Router#Server Components#Debugging
A server component crate handing a glowing request card across a cyan boundary gate, an amber lock beside it

Introduction & Quick Summary

text
Error: Functions cannot be passed directly to Client Components unless you explicitly expose it by marking it with "use server". Or maybe you meant to call this function rather than return it. {prop: "onClick", value: function handleSelect() {}}

A Server Component and a Client Component do not share a JavaScript heap. The props you pass from server to client are serialized into the RSC payload, and a function has no serialized form unless React knows it is a server reference. This error is the boundary rejecting the prop, not a hook or a rendering problem.

The three legitimate answers:

  • The function is a user interaction — move it into the Client Component and keep the server component free of handlers.
  • The function must run on the server — mark it "use server". It becomes a server action, a reference the client can call.
  • The function is only formatting or lookup logic — pass data instead of the function: a preformatted string, an enum-like key, or a plain map the client can switch on.

Or maybe you meant to call this function rather than return it is a separate, common cause: onClick={handleClick()} passes the return value of the call, which is often a function. Remove the parentheses.

FailureWhat is passedFix
onClick from a server filePlain functionMove handler into the client component
onClick={handle()}Return value, often a functionCall only inside the handler
Server mutationasync function not marked"use server" directive
Formatter/deps injectionHelper functionPass data, switch on a key
Context provider value with callbacksFunction in an objectKeep provider + state in one client file
Library componentonChange default handlerWrap it in your own client wrapper

Core Mechanics, Signatures & Reproducible Setup

The server renders a Server Component to a serialized tree. Every prop crossing into a Client Component must fit React's serialization format:

  • primitives: string, number, bigint, boolean, undefined, null
  • plain objects with no prototype beyond Object, arrays and iterables of serializable values
  • Date, Map, Set, FormData, ArrayBuffer, typed arrays
  • promises resolved in a use() boundary
  • plain JSX elements already created on the server
  • server actions (functions marked "use server") and globally registered symbols

Class instances, functions without the directive, and symbols created outside Symbol.for are not serializable and fail here.

Reproduction:

tsx
// app/products/page.tsx (Server Component) import { FilterBar } from "./filter-bar"; export default async function Page() { const products = await db.product.findMany(); const onFilter = (q: string) => console.log(q); // plain closure return <FilterBar products={products} onFilter={onFilter} />; }
tsx
// app/products/filter-bar.tsx "use client"; export function FilterBar({ products, onFilter }: { products: { id: string; name: string }[]; onFilter: (q: string) => void; }) { return <input onChange={(e) => onFilter(e.target.value)} />; }

The server component compiles; the request fails at render. The server-action variant runs:

ts
// app/actions.ts "use server"; export async function logFilter(q: string) { await db.filterEvent.create({ data: { q } }); }
tsx
// app/products/page.tsx import { logFilter } from "@/app/actions"; return <FilterBar products={products} onFilter={logFilter} />;

A server action is callable from the client, but it is a network call, not a local function: it cannot close over server-only state, its arguments must be serializable, and it always returns a promise.

Key Comparison Table

PatternFunction crosses the boundaryNetwork round tripUse when
Handler inside client componentNoNoPure UI interaction
"use server" actionYes, as a referenceYesMutation, form submit
Server action with .bind(null, id)Yes, bound args serializedYesPer-row actions
Pass data, switch on keyNoNoFormatting, labels, sort modes
children prop of rendered JSXNoNoWrapping a client layout
Context provider in client fileNo, stays client-sideNoShared interactive state
Prop valueSerializableError if passed
"asc", 42, true, nullYes—
{ sort: "asc", tags: ["a"] }Yes—
new Date(), new Map()Yes—
() => {} in a server fileNoThis error
async () => {} with "use server"Yes—
new PrismaClient() / class instanceNo"Only plain objects..." variant
Symbol("x")NoSerialization error

Practical Edge Cases, Error Fixes & Deep Dive Code Examples

Case 1: Keep the interaction client-side

tsx
// app/inbox/page.tsx — Server Component import { InboxList } from "./inbox-list"; export default async function Page() { const messages = await db.message.findMany({ orderBy: { at: "desc" } }); return <InboxList messages={messages} />; // data only }
tsx
// app/inbox/inbox-list.tsx "use client"; import { useState } from "react"; export function InboxList({ messages }: { messages: { id: string; subject: string }[] }) { const [selected, setSelected] = useState<string | null>(null); return ( <ul> {messages.map((m) => ( <li key={m.id} aria-selected={m.id === selected}> <button onClick={() => setSelected(m.id)}>{m.subject}</button> </li> ))} </ul> ); }

This is the default fix and it removes a network hop: push state down to the smallest component that interacts, and keep the data fetch on the server.

Case 2: Per-row server actions with bound arguments

tsx
// app/inbox/row-actions.tsx import { archive } from "@/app/actions"; export function RowActions({ id }: { id: string }) { return ( <form action={archive.bind(null, id)}> <button type="submit">Archive</button> </form> ); }
tsx
<form action={archive}> <input type="hidden" name="id" value={id} /> <button type="submit">Archive</button> </form>

Bound arguments are captured in the payload, so prefer the hidden input when the id is already available.

Case 3: "Only plain objects" — a class instance behind the same error

tsx
// server const invoice = await prisma.invoice.findUniqueOrThrow({ where: { id } }); return <InvoiceView invoice={invoice} />; // Decimal, Date, class instances

Prisma's Decimal and ORM entities carry prototypes and methods. Map explicitly:

tsx
const invoice = await prisma.invoice.findUniqueOrThrow({ where: { id } }); const view = { id: invoice.id, total: invoice.total.toString(), issuedAt: invoice.issuedAt.toISOString(), }; return <InvoiceView invoice={view} />;

The client receives plain data and formats for display.

Case 4: A context provider that holds callbacks

tsx
// app/layout.tsx — Server Component import { ToastProvider } from "./toast"; export default function Layout({ children }: { children: React.ReactNode }) { return ( <ToastProvider onDismiss={(id) => console.log(id)}> {children} </ToastProvider> ); }

The provider is a Client Component, so onDismiss is an unserializable prop. Move the callback inside the provider file and expose a stable API:

tsx
// app/toast.tsx "use client"; import { createContext, useContext, useState } from "react"; const ToastCtx = createContext<{ push: (m: string) => void } | null>(null); export function ToastProvider({ children }: { children: React.ReactNode }) { const [items, setItems] = useState<string[]>([]); const push = (m: string) => setItems((s) => [...s, m]); return ( <ToastCtx.Provider value={{ push }}> {children} {items.map((m, i) => <p key={i}>{m}</p>)} </ToastCtx.Provider> ); }

Case 5: Passing a formatter by name instead of by value

tsx
// server <Price amount={1999} format={(n) => `$${(n / 100).toFixed(2)}`} /> // error
tsx
// client const FORMATTERS = { usd: (n: number) => `$${(n / 100).toFixed(2)}`, } as const; export function Price({ amount, currency }: { amount: number; currency: keyof typeof FORMATTERS }) { return <span>{FORMATTERS[currency](amount)}</span>; }

Formatting on the client also avoids hydration mismatches.

Common Compilation/Runtime Mistakes & Version Gotchas

  • "use server" in a Client Component file. The directive must be at the top of an async server file or an async function inside a Server Component. Placing it in a "use client" file is a build error.
  • Server actions must be async. A synchronous function marked "use server" fails at build time; the client always gets a promise.
  • Arguments are serialized too. A server action that takes a Date is fine; one that takes a class instance or another function is not.
  • A parenthesized handler. onClick={save()} passes the return value of the call, which for a curried factory or a resolver is a function built on the server. Remove the parentheses.
  • "use server" does not make closures work. A server action cannot read the enclosing request's cookies() unless it calls cookies() itself; state captured at module scope is shared by all requests.
  • Turbopack messages. The Turbopack builder reports the same defect as Only plain objects, and a few built-ins, can be passed to Client Components from Server Components, naming the offending prop path.
  • Memoized callbacks are still functions. useCallback results cannot cross the boundary; moving the hook into the client component is the only fix.

Inspect the failing prop payload by logging the object and formatting it with the JSON formatter; the serializer's own message names the path, and the diff tool helps confirm a prop was removed in a refactor. For the HTTP layer around a server action, the curl builder reproduces the POST that Next.js sends.

Primary references: "use client" defines which values can cross the server-client boundary, and Server and Client Components covers the composition patterns allowed in the App Router.

Official references

primary documentation

The Next.js documentation that defines the behaviour this guide explains.

Try matching browser tools

All tools

Small utilities that fit Next.js work — they run entirely in this browser tab, so nothing you paste leaves your device.

All Next.js guides

More in Next.js

All Next.js guides

The guides filed next to this one in Next.js, in library order.