In my client component I want to create a new Todo:
"use client";
const ClientComp:FC<{ createTodo: (title:string) => void }> = ({ createTodo }) => {
return (
<button onClick={() => createTodo("First Todo")}>ADD TODO</button>
)
}
Now in my server component, I would like to actually insert a new row in the db when this button is clicked:
const ServerComp:FC<{}> = () => {
const createTodo = async (title:string) => {
"use server";
const { error } = await supabase.from("todos")
.insert([{ id: user.id, title }]);
return error
}
return (
<ClientComp createTodo={createTodo} />
)
}
But I get an error log in the server console saying:
Error: Functions cannot be passed directly to Client Components unless you explicitly expose it by marking it with "use server". [..., function] ^^^^^^^^ at stringify (<anonymous>)
What am I doing wrong here?