NextPlayground

useActionState

The useActionState hook connects a form to a server action and keeps the action's latest return value as state. The signup form below validates on the server: errors come back per field, submitted values are echoed so the form isn't wiped, and the built-in isPending flag drives the loading state — no useState bookkeeping required. It also works before JavaScript loads, since the form posts to the action natively.

react.dev/reference/react/useActionState

Tip: usernames ryan, admin, and test are taken — try one to see server-side validation errors survive the round-trip while your input is preserved.

useActionState Demo