What problem does it solve?
Handle UI-driven data mutations in Next.js applications without creating separate API routes by invoking server-side functions directly from components. This removes boilerplate for form handling, centralizes validation and business logic on the server, and makes progressive enhancement and optimistic UI flows straightforward.
Core Features & Use Cases
- Invoke server-side functions with the 'use server' directive to handle form submissions, file uploads, and CRUD operations.
- Trigger cache revalidation with revalidatePath or revalidateTag and perform redirects after mutations.
- Integrate validation and pending/error state with useActionState and enable optimistic updates with useOptimistic and useTransition.
- Use Case: Build a create/edit/delete workflow for a blog or todo app where forms submit to server actions, the UI shows optimistic changes, and pages are revalidated after the mutation.
Quick Start
Create a Server Action named createPost that accepts FormData, validates title and content, saves the record to the database, calls revalidatePath('/blog'), and redirects the user to /blog.