Can components that use Server Actions be server components?
Unanswered
Giant panda posted this in #help-forum
Giant pandaOP
In chapter 12 of the tutorial (https://nextjs.org/learn/dashboard-app/mutating-data#using-forms-with-server-actions), under "Using Forms with Server Actions", the code snippet below is confusing. How can
If I omit
Page here be a server component if it has a form/interactivity?If I omit
'use server', the error I get is Functions cannot be passed directly to Client Components unless you explicitly expose it by marking it with "use server". Is the error message incorrect or is the Page actually a client component?// Server Component
export default function Page() {
// Action
async function create(formData: FormData) {
'use server';
// Logic to mutate data...
}
// Invoke the action using the "action" attribute
return <form action={create}>...</form>;
}3 Replies
Asian black bear
That’s not client side interactivity per se.
Real server actions unlike event handlers can be passed to components with the action and formAction prop in server components by design
Under the hood it gets wired up properly.