Progressive Enhancement

useActionState for forms that work with and without JavaScript

Create Todo (Progressive)

This form uses formProps for native HTML fallback and formAction(FormData) for JS-enhanced submission.

State

pending:falsestate:nullerror:nullformProps:{"action":"/api/_actions/create-validated-todo","method":"post"}

Try It

Enter "Buy milk" or "Walk dog" to trigger a server-side validation error via returnValidationErrors.

Submit empty to see Zod validation.

How it works

import { createValidatedTodo } from '#actions'

const { state, error, pending, formAction, formProps } =
  useActionState(createValidatedTodo)

// Template:
// <form v-bind="formProps"
//       @submit.prevent="formAction(new FormData($event.target))">
//   <input name="title" />
//   <button :disabled="pending">Create</button>
// </form>

// formProps provides { action, method } for native
// HTML form submission when JS is disabled.
// formAction converts FormData to plain object and
// executes the action with full type safety.