# useActionState()

> The `useActionState()` hook in React updates state based on the result of an action.

## How do I use useActionState in React?

The hook that takes an action function and an initial state and returns the current state, a wrapped action and the pending flag. Commonly used with forms to show the result of a submission or validation errors.

- Topic: Hooks
- Type: hook

## Example

Wrong:

```jsx
async function signup(formData) {
  const email = formData.get('email');
  return await createUser(email);
}
const [state, formAction, isPending] = useActionState(signup, null);
```

Right:

```jsx
async function signup(prevState, formData) {
  const email = formData.get('email');
  return await createUser(email);
}
const [state, formAction, isPending] = useActionState(signup, null);
```

The action receives the previous state first and the form data second, so `formData.get()` works on the right argument.

## Common mistakes

- Reading `formData` from the first argument, which is actually the previous state.

## Key points

- `useActionState` is imported from 'react', not the old `useFormState` from 'react-dom'.
- The action takes `(prevState, formData)`, with the previous state as the first argument.
- The returned `isPending` drives the button state instead of a separate `useState` flag.

## Interview questions

### What is the difference between useActionState and useFormState?

They are the same idea. `useFormState` from 'react-dom' was renamed to `useActionState` and moved to 'react'; the old name is deprecated.

### Can I use useActionState without a form?

Yes. Call the returned dispatch function inside `startTransition`, for example from a button click handler.

### Does useActionState work with Server Functions?

Yes. Pass a function marked with `'use server'` as the action, and the returned state comes back from the server.

## Related cards

- [Actions](https://wonderium.dev/react/actions.md)
- [useFormStatus()](https://wonderium.dev/react/use-form-status.md)
- [useOptimistic()](https://wonderium.dev/react/use-optimistic.md)
- [Server Actions](https://wonderium.dev/react/server-actions.md)
- [useTransition()](https://wonderium.dev/react/use-transition.md)

---

- Level: [React](https://wonderium.dev/react.md)
- HTML version: https://wonderium.dev/react/use-action-state
- Last updated: 2026-11-25
