Next.js: Event handlers cannot be passed to Client Component props
#111Error
Error: Event handlers cannot be passed to Client Component props.
<button onClick={function onClick} children=...>
If you need interactivity, consider converting part of this to a Client Component.Why it happens, and why this works
A Server Component passed a function (onClick, onChange...) to an element or component. Functions can't be sent from the server to the browser.
Fix
Move the interactive part into a Client Component: create e.g. LikeButton.tsx starting with "use client" that owns the onClick, and render <LikeButton /> from the server page. To run server code on click, use a Server Action (a function with "use server") passed to a form action instead.
Did it work?
No reports yetRelated fixes
Next.js: You're importing a component that needs useState. It only works in a Client Component
#110You're importing a component that needs `useState`. This React Hook only works in a Client Component. To fix, mark the file (or its parent) with the `"use client"` directive.
Error: Functions cannot be passed directly to Client Components unless you explicitly expose it by marking it with "use server"
#150Error: 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.
Invalid hook call. Hooks can only be called inside of the body of a function component
#151Error: Invalid hook call. Hooks can only be called inside of the body of a function component. This could happen for one of the following reasons: 1. You might have mismatching versions of React and the renderer (such as React DOM) 2. You might be breaking the Rules of Hooks 3. You might have more than one copy of React in the same app