Skip to main content
React Server Actions are server functions that handle form submissions in Next.js. They receive FormData automatically when used as a form action.
Always verify authentication and authorization inside each Server Action, even if the form is rendered only on an authenticated page.

Basic form submission

Define a Server Action inline in a Server Component:
For forms with many fields, use Object.fromEntries(formData) to extract all values at once.

Passing additional arguments

Use JavaScript’s bind to pass additional arguments to a Server Action:
bind works in both Server and Client Components and supports progressive enhancement.

Form validation

Use HTML attributes for basic validation:

Validation errors and pending states

Use useActionState to display validation errors and track pending state in a Client Component:

Submit button with useFormStatus

For a reusable submit button component, use useFormStatus:
In React 19, useFormStatus returns additional keys: data, method, and action. In earlier versions, only pending is available.

Optimistic updates

Use useOptimistic to update the UI immediately before the server responds:

Nested form elements

Call Server Actions from nested <button>, <input type="submit">, and <input type="image"> elements using the formAction prop. This allows multiple actions within a single form:

Programmatic submission

Trigger form submission programmatically using requestSubmit():