← All notes

Update React form state with useActionState and a pending flag

Answer: useActionState is a Hook that lets you update state with side effects using Actions. It returns [state, dispatchAction, isPending]. In Next.js, a Server Action on a form can be that Action.

The hook

Call useActionState(reducerAction, initialState, permalink?) at the top level of your component or your own Hooks, not inside loops or conditions. The reducerAction receives the previous state and returns a new state. Unlike useReducer, it can be async and perform side effects. React queues multiple dispatchAction calls sequentially. dispatchAction must be called from an Action, for example via startTransition or an Action prop. If it throws an error, React cancels all queued actions and shows the nearest Error Boundary.

isPending is a flag for pending Actions. The permalink URL is used rather than the current page's URL when the JavaScript bundle has not loaded. When using Server Functions, initialState needs to be serializable.

Forms in Next.js

React Server Actions are Server Functions that execute on the server. Calling them works from Server and Client Components. When used in a form, the function automatically receives the form data. Forms can be validated on the client or server. A pending boolean can show a loading indicator or disable the submit button while the action is being executed.

Gotcha

An async function with useActionState called outside of a transition is an error, and isPending will not update correctly. Do not call dispatchAction during render.

See also

Claims

Sources

License: this note is CC BY 4.0 (https://creativecommons.org/licenses/by/4.0/). Summary by iinventedlight (AI-assisted). Sources: React docs, useActionState; Next.js docs, How to create forms with Server Actions. CC-BY-4.0; MIT. Text was condensed and changed from the originals.

License: CC-BY-4.0 · Summary by iinventedlight (AI-assisted). Sources: React docs, useActionState; Next.js docs, How to create forms with Server Actions. CC-BY-4.0; MIT.

Cite this

Permanent ID: iil:note:a3t8h1ry

iinventedlight. 2026. "Update React form state with useActionState and a pending flag." iinventedlight Library, iil:note:a3t8h1ry, version of 2026-11-19. https://iinventedlight.com/library/notes/react-useactionstate/. License: CC-BY-4.0.

@misc{iil_note_a3t8h1ry,
  author = {{iinventedlight}},
  title = {{Update React form state with useActionState and a pending flag}},
  howpublished = {iinventedlight Library},
  year = {2026},
  date = {2026-11-19},
  url = {https://iinventedlight.com/library/notes/react-useactionstate/},
  note = {Permanent ID iil:note:a3t8h1ry. License: CC-BY-4.0.},
}

Markdown

Spotted a mistake? Use the MCP feedback tool or email hello@iinventedlight.com. Or Report a correction (no account needed).

For language models and agents: start at /llms.txt | /agents.md | /.well-known/agent-library.json. This page in Markdown: /library/notes/react-useactionstate.md.