Maaz Zindani

Loading the index…

↑↓ move↵ openesc close4072 pages
Next.js and React

Next.js: Event handlers cannot be passed to Client Component props

ErrorEvent handlers cannot be passed to Client Component props.

Short answer

In the App Router, pages and layouts are Server Components, and a function cannot be sent from the server to the browser as a prop. onClick on a plain element in a Server Component, or a callback prop passed to a Client Component, causes this error. Put the handler inside a file marked use client, or pass a Server Function marked use server.

  • Applies to Next.js 15, Next.js 16, React 19
  • Updated
  • By Maaz Zindani, Senior Software Engineer

Fix it fast

  1. 1Find out which cause you have

    The error names the element and the prop, for example onClick. Find that JSX and check the first line of the file it lives in. No 'use client' directive means it is a Server Component, and the handler must move.

    head -3 app/page.tsx
    grep -rnE "on[A-Z][a-zA-Z]+=\{" app | head -30
  2. 2Match what you see, then jump to its fix

    1. 1The file has no 'use client' line and renders a button, input or form with onClick, onChange or onSubmit.A handler is written in a Server ComponentFix
    2. 2The component receiving the prop already has 'use client', but the page that renders it passes onSave, onSelect or a similar callback.A function is passed as a prop from server to clientFix
    3. 3The handler is inside a library component and your own file has no onClick of its own.A third-party component that needs the browser is used in a Server ComponentFix

What does the error look like?

  • Event handlers cannot be passed to Client Component props.
  • onClick in a Server Component, or a callback prop sent to a Client Component

Cause 1 of 3

A handler is written in a Server Component

1Check

State and event handlers need a Client Component. Next.js treats layouts and pages as Server Components by default.

head -5 app/page.tsx

2Fix

Move only the interactive part into its own file that starts with 'use client', and import it into the page. Keep the page on the server, so data fetching stays there.

// app/ui/like-button.tsx
'use client'
import { useState } from 'react'

export default function LikeButton({ likes }: { likes: number }) {
  const [count, setCount] = useState(likes)
  return <button onClick={() => setCount(count + 1)}>{count} likes</button>
}

// app/page.tsx (still a Server Component)
import LikeButton from '@/app/ui/like-button'
export default function Page() {
  return <LikeButton likes={12} />
}

3Verify

Reload the page and click the button. The count changes and the error is gone.

npm run dev

Confirmed by nextjs.org

Did this fix it?

Cause 2 of 3

A function is passed as a prop from server to client

1Check

Props that cross from a Server Component to a Client Component must be serializable. A plain function, a class instance or an unregistered symbol is not.

grep -rnE "<[A-Z][A-Za-z]+[^>]* on[A-Z][A-Za-z]*=\{" app | head -30

2Fix

Either define the function inside the Client Component, or write it as a Server Function with 'use server' and pass that. Functions exported from a module that has use client are fine inside that module's tree.

// app/actions.ts
'use server'
export async function saveNote(formData: FormData) {
  // write to the database here
}

// app/page.tsx (Server Component)
import { saveNote } from './actions'
import NoteForm from './ui/note-form'
export default function Page() {
  return <NoteForm action={saveNote} />
}

3Verify

Submit the form. The request reaches the Server Function and no prop error is shown.

npm run dev

Confirmed by react.dev

Did this fix it?

Cause 3 of 3

A third-party component that needs the browser is used in a Server Component

1Check

A library that uses state or handlers but does not mark its entry with use client cannot run in a Server Component.

grep -rn "use client" node_modules/PACKAGE/dist 2>/dev/null | head -3

2Fix

Wrap the library component in your own Client Component file and import that wrapper instead.

// app/carousel.tsx
'use client'
import { Carousel } from 'acme-carousel'
export default Carousel

3Verify

Import the wrapper in the page and reload.

npm run dev

Confirmed by nextjs.org

Did this fix it?

How do I stop it coming back?

  • Add 'use client' to small leaf components that need state or events, not to whole pages.
  • Pass data as props from the server, and keep callbacks inside the Client Component or as Server Functions.
  • Keep forms on Server Functions with the form action prop where you can.

Sources

How was this page made?

I drafted this page with AI assistance from the official documents listed under Sources. Every cause above names the document that confirms it. I have not reproduced this fix on a machine of my own yet, so read it as documented guidance, not a test report. Found a mistake? Tell me.

Which stack is behind this page?

Projects of mine built on the same technologies:

Related fixes

Web apps

next/link throws React.Children.only on its children

Error: React.Children.only expected to receive a single React element child.

React.Children.only accepts exactly one React element and throws for anything else, including an array with one item.

3 causes, each with a fix

Next step

Want this handled for good?

I look after servers, apps and releases end to end. Tell me what keeps breaking.