Course contentsShow
← React
Lesson 1611 of 2,39639. Server Components in PracticeFree lesson

The action Prop on Forms

Using the native action prop with server actions for progressive enhancement and no-JS forms.

The action Prop on Forms

What you'll learn: How to use the native HTML action prop with server actions to create forms that work even without JavaScript.

The Built-In Form Enhancement

You've already seen server actions called in various ways, but React Server Components bring back a classic web pattern with a modern twist: the action prop on <form> elements. Instead of pointing to a URL (like traditional HTML forms), you can pass a server action function directly as the action prop.

When a user submits the form, React automatically:

  • Prevents the default page reload
  • Calls your server action with the form's FormData
  • Handles the response seamlessly

Progressive Enhancement Magic

Here's the game-changer: if JavaScript fails to load or is disabled, the form still works. React falls back to native browser form submission behavior, and your server action still executes. This is called progressive enhancement—your app works at a basic level for everyone, then gets better with JavaScript.

// In a Server Component
async function createTodo(formData: FormData) {
  'use server'
  const title = formData.get('title')
  // Save to database...
}

export default function TodoForm() {
  return (
    <form action={createTodo}>
      <input name="title" required />
      <button type="submit">Add Todo</button>
    </form>
  )
}

The form works immediately—no onSubmit, no preventDefault(), no manual form state. With JS enabled, it's smooth and instant. Without JS, it still submits and works.

Key Takeaway: The action prop connects forms directly to server actions, providing both a modern React experience with JavaScript and a fallback that works without it—the best of both worlds.