Event handlers cannot be passed to Client Component props

On this page

Short answer

A Server Component is passing a function, such as an onClick handler, as a prop. Functions can't cross from server to client. Move the handler into the component that uses it, in a file that starts with 'use client'. Then pass only data, such as strings, numbers or plain objects, from the server parent.

Find a fix pack

Checklists and prompts for Supabase security, Stripe payments and deploys. Each pack is $24, or $49 for all three.

The exact error you'll see

React throws this error. The text below is from React's error-code list (error 374):

Event handlers cannot be passed to Client Component props.
If you need interactivity, consider converting part of this to a Client Component.

Source: https://github.com/react/react/blob/main/scripts/error-codes/codes.json (opens in a new tab)

In the real message, React inserts extra detail after the first sentence.

Applies to

  • Next.js App Router pages and layouts, which are Server Components by default
  • Any prop that takes a function: onClick, onChange, onSubmit and similar
  • Apps generated by v0 or Cursor and deployed to Vercel

Why it happens

  • Pages and layouts run on the server. Next.js: "By default, layouts and pages are Server Components."
  • Props sent to a Client Component must be serializable. Next.js says the props of Client Components "need to be in a format that React can serialize." Its own example marks a function prop with "❌ Function is not serializable."
  • Event handlers belong in client code. React: "event handlers like onClick can only be defined in Client Components."
  • Adding 'use client' to the child isn't enough. The child can be a Client Component and the error still fires, because the function was created in the server parent.

How to fix it, step by step

  1. Read the component and prop named in the error. Find the file where that function is defined.
  2. If that file has no 'use client' directive, it's a Server Component. Move the interactive part into its own file.
  3. Put 'use client' at the very top of the new file. Next.js says to add it "at the top of the file, before any imports," and that it "cannot be placed inside a component or function."
  4. Define the handler inside the Client Component. This is React's button example with the directive added:
'use client'

export default function Button() {
  function handleClick() {
    alert('You clicked me!')
  }
  return <button onClick={handleClick}>Click me</button>
}

Pass the function, don't call it. React: "Functions passed to event handlers must be passed, not called." onClick={handleClick()} runs it during render.

  1. In the server parent, render the Client Component and pass it data only. Next.js shows this with a server page that fetches a post and passes it to a <LikeButton> that "handles client-side interactivity."
  2. If the click needs to run code on the server, such as saving to a database, use a Server Function. Mark an async function with 'use server' and pass it as a form action. React will "supply the form's FormData as the first argument." Treat its arguments as untrusted input and check that the user is allowed to make the change.

What the docs don't spell out

  • Server Functions are the one kind of function you can pass. React's list of serializable props includes "Functions that are Server Functions." Ordinary functions are not on it. (React 'use client' (opens in a new tab))
  • Keep the client part small. Once a file has 'use client', "all of its imports and the components it directly renders are included in the client bundle." Next.js suggests marking only the interactive components, not whole sections of the page. (Server and Client Components (opens in a new tab))
  • A Server Function call is a network request. React says calling one sends "a serialized copy of any arguments passed." It's not a drop-in replacement for a click handler that only changes the UI. (React 'use server' (opens in a new tab))

How to check it worked

  • Reload the route. The error no longer appears.
  • Click the control. The handler runs on click, not when the page loads.
  • Search the server parent for other function props passed to Client Components.

Sources

  1. https://github.com/react/react/blob/main/scripts/error-codes/codes.json (opens in a new tab): exact text of React error 374
  2. https://nextjs.org/docs/app/getting-started/server-and-client-components (opens in a new tab): Server Components by default, LikeButton example, client bundle and small boundaries
  3. https://nextjs.org/docs/app/api-reference/directives/use-client (opens in a new tab): directive placement, serializable props, function-prop example
  4. https://react.dev/reference/rsc/use-client (opens in a new tab): onClick only in Client Components, serializable types including Server Functions
  5. https://react.dev/learn/responding-to-events (opens in a new tab): button example, pass handlers rather than call them
  6. https://react.dev/reference/rsc/use-server (opens in a new tab): Server Functions, form action with FormData, serialized arguments, untrusted input

Tool to consider: Vercel.

Find a fix pack

Checklists and prompts for Supabase security, Stripe payments and deploys. Each pack is $24, or $49 for all three.