Forms & Actions in React

From the React Router v7 cheat sheet · Forms & Actions · verified Jul 2026

Forms & Actions

Handling forms with actions and progressive enhancement

typescript
import { Form, useActionData, useNavigation } from 'react-router'

// Action function
export async function action({ request, params }) {
  const formData = await request.formData()
  const title = formData.get("title")

  try {
    const post = await createPost({ title })
    return redirect(\`/posts/\${post.id}\`)
  } catch (error) {
    return { error: error.message }
  }
}

// Form component
export default function NewPost() {
  const actionData = useActionData<typeof action>()
  const navigation = useNavigation()
  const isSubmitting = navigation.state === "submitting"

  return (
    <Form method="post">
      <input name="title" required />
      {actionData?.error && (
        <p className="error">{actionData.error}</p>
      )}
      <button disabled={isSubmitting}>
        {isSubmitting ? "Creating..." : "Create Post"}
      </button>
    </Form>
  )
}
💡 Forms work without JavaScript - progressive enhancement
⚡ Use fetcher.Form for non-navigation forms
📌 Actions handle POST, PUT, PATCH, DELETE methods
🟢 Return json() with validation errors for form feedback
formsactionsmutations

Continue with React Router v7

Save the full cheat sheet or work through every related task.

Back to the full React Router v7 cheat sheet