Error: Event handlers cannot be passed to Client Component props.
Unanswered
Satin Angora posted this in #help-forum
Satin AngoraOP
I am sending down
The full error I'm getting is:
What may be the issue? I'm blocked by this 😦 I'm trying to call functions from my Firestore repository.
async event handlers to a component, where it gets called together with async function handleSubmit(event: FormEvent<HTMLFormElement>) {
event.preventDefault()
const formData = new FormData(event.currentTarget/*.target*/)
await onSubmit(formData)
if (doHideFormAfterSubmit) setIsFormSubmitted(true)
} and this function is passed to the onSubmit property of the <form> element.The full error I'm getting is:
- error node_modules\next\dist\compiled\react-server-dom-webpack\cjs\react-server-dom-webpack-server.edge.development.js (1902:12) @ resolveModelToJSON
- error Error: Event handlers cannot be passed to Client Component props.
<... name=... submitButtonLabel=... onSubmit={function} afterSubmitChildren=... children=...>
^^^^^^^^^^
If you need interactivity, consider converting part of this to a Client Component.
at stringify (<anonymous>)
null
- error node_modules\next\dist\compiled\react-server-dom-webpack\cjs\react-server-dom-webpack-server.edge.development.js (1902:12) @ resolveModelToJSON
- error Error: Event handlers cannot be passed to Client Component props.
<... name=... submitButtonLabel=... onSubmit={function} afterSubmitChildren=... children=...>
^^^^^^^^^^
If you need interactivity, consider converting part of this to a Client Component.
at stringify (<anonymous>)
digest: "3042938249"
nullWhen I turn the callbacks passed down to the form component into server actions, this error disappears, but then I get this warning:Warning: Detected multiple renderers concurrently rendering the same context provider. This is currently unsupported. The warning itself is long and repeats a few times. Also, my callback doesn't run when I turn it into a server action.What may be the issue? I'm blocked by this 😦 I'm trying to call functions from my Firestore repository.
12 Replies
Pacific herring
hello
In nextJS 13, if you dont have "use client" at the top of the page then every page and component will be automatically server-side
if i were you, i'd create a new file and create my component and handler there, adding "use client" at the top of the page. doing so, it'll be client side and then you can use the handler.
Then you can export your component in server side stuff as well
look
my client side component
then I export it and import the component somewhere else
in a server-side page
@Satin Angora
Asiatic Lion
@Pacific herring I understand this, but if I want to async a function I need to be on client-side to use onClick, and I can't pass event handlers to Client Component props