Functions cannot be passed directly to Client Components
Answered
American Sable posted this in #help-forum
American SableOP
Does anyone know why this component errors with
I thought this was SSR by default?
KycForm.tsx
[ Server ] Error: Functions cannot be passed directly to Client Components unless you explicitly expose it by marking it with "use server".
I thought this was SSR by default?
KycForm.tsx
import Form from 'next/form'
import { Input } from "@/components/ui/input";
export default function KycForm() {
function doSomething(formData){
const query = formData.get("query");
alert(`You searched for '${query}'`);
}
return (
<Form action={doSomething} replace={true}>
<Input name="query" />
<button type="submit">Submit</button>
</Form>
)
}
Answered by chisto
your server action needs "use server" directive
function doSomething(formData){
"use server"
const query = formData.get("query");
alert(
function doSomething(formData){
"use server"
const query = formData.get("query");
alert(
You searched for '${query}'
);2 Replies
your server action needs "use server" directive
function doSomething(formData){
"use server"
const query = formData.get("query");
alert(
function doSomething(formData){
"use server"
const query = formData.get("query");
alert(
You searched for '${query}'
);Answer
American SableOP
Ahhh didn't realise I could put that inside a function like that