Error: Functions cannot be passed directly to Client Components unless you explicitly expose it by marking it with "use server"
#150Error
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.
Why it happens, and why this works
Props from a Server Component to a Client Component are serialized and sent over the network, and an ordinary function can't be serialized. Only Server Actions (functions marked "use server") can cross that boundary, as a reference.
Fix
Pick one: 1. Move the handler into the client component (the file with "use client"), e.g. define onClick there instead of passing it in. 2. If it should run on the server, make it a Server Action: put "use server" at the top of the function body (or in a separate actions file) and pass that. 3. If you meant to pass a value, call the function on the server and pass its result.
Did it work?
No reports yetRelated fixes
Next.js: Event handlers cannot be passed to Client Component props
#111Error: 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.
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
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.