Functions

React useActionState

React useActionState returns current state, an action dispatcher and a pending flag. Its action takes previous state before payload. When using a Server Function, use serializable initial state and result. The sample is a client-only validation demo, not durable persistence. Source: https://react.dev/reference/react/useActionState. Documentation-reviewed illustrative draft; installed declarations and runtime not verified.

Formal Syntax & Structure

nextjs syntaxnextjs
useActionState(action, initialState, permalink?)

Working Example

Example Snippetnextjs
// app/title-check/page.tsx — client-only teaching form; no persistence'use client';import { useActionState } from 'react';type State = { message: string };async function check(_: State, data: FormData): Promise<State> {  const value = data.get('title');  return { message: typeof value === 'string' && value.trim().length >= 3    ? 'Title accepted for review' : 'Enter at least three characters' };}export default function Page() {  const [state, action, pending] = useActionState(check, {message: ''});  return <form action={action}>    <label htmlFor="title">Title</label><input id="title" name="title" />    <button disabled={pending}>{pending ? 'Checking…' : 'Check'}</button>    <p role="status">{state.message}</p>  </form>;}
Next.js Reference