Skip to main content

App Router Mastery

Server Actions and Forms

0:00
LearnStep 1/5

Understanding Server Actions

Server Actions: RPC for the Modern Web

Server Actions are async functions that run on the server but can be called directly from Client Components. They're like having an API endpoint inline with your component code.

The Old Way vs Server Actions

tsx
tsx
Key Benefits:
  • Progressive enhancement - works without JavaScript
  • Automatic serialization of FormData
  • Built-in revalidation integration
  • Type-safe with TypeScript

Server Action Rules

  1. Must be marked with 'use server' directive
  2. Can only be async functions
  3. Arguments must be serializable (no functions, classes)
  4. Can be defined inline or in separate files

Inline vs Module Server Actions

tsx