Migration from useFormState
What you'll learn: How to update your React 18 useFormState code to React 19's useActionState with minimal changes.
Why the Name Changed
In React 18's experimental releases, the hook for managing form actions was called useFormState. React 19 renamed it to useActionState because the functionality isn't limited to forms—you can use it anywhere you need server actions with pending states and progressive enhancement.
The Migration Path
The good news: the signature didn't change. If you have existing useFormState code, you're essentially doing a find-and-replace:
// React 18 (experimental)
import { useFormState } from 'react-dom';
function MyForm() {
const [state, formAction] = useFormState(serverAction, initialState);
// ... rest of your code
}
// React 19
import { useActionState } from 'react';
function MyForm() {
const [state, formAction, isPending] = useActionState(serverAction, initialState);
// ... rest of your code
}
What Actually Changed
- Import location: Moved from
'react-dom'to'react' - Hook name:
useFormState→useActionState - Third return value: React 19 added
isPending(in experimentaluseFormState, you neededuseFormStatusseparately)
The action function itself, the state shape, and error handling patterns all work identically.
Why This Matters
The rename clarifies that this pattern works for any action, not just form submissions. You might use useActionState for button clicks, background sync operations, or any async state transition that benefits from pending states and error handling.
Key Takeaway: Migrating from useFormState to useActionState is mostly a rename—same concept, same API, clearer purpose, and now with isPending built in.