What Are Server Actions?

Server Actions provide a way to define functions that execute on the server and can be invoked from supported React interactions such as forms.

They are useful for operations such as creating records, updating profiles, deleting resources, submitting feedback, or changing account settings.

The major advantage is that the mutation logic can remain on the server instead of requiring a manually created HTTP endpoint for every form operation.

Basic Server Action
'use server';

export async function createComment(formData: FormData) {
  const text = formData.get('text');

  if (typeof text !== 'string' || !text.trim()) {
    throw new Error('Comment is required');
  }

  await db.comment.create({
    data: { text }
  });
}
💡 The action executes on the server and receives submitted form data.
Key Takeaways
  • Server Actions are designed for server-side mutations.
  • They can simplify form submission architecture.
  • Actions still require authentication and authorization.