Windows Errors? Fix Them Before They Spread
Repair common Windows errors and clear accumulated junk for a smoother, more stable PC - no reinstall needed.Free scan · no reinstallOutdated Drivers Are Slowing You Down
One free scan finds every outdated or missing driver and matches the right update for your exact hardware.Free scan · exact hardware matchiTechGuides is reader-supported. When you buy through links on our site, we may earn an affiliate commission. As an Amazon Associate I earn from qualifying purchases. Learn more
An Action in React 19 is a function that performs a data mutation and then updates state in response. React can run Actions inside transitions and attach them to form action and formAction props, so pending state and optimistic UI can be handled in one workflow. The three hooks that usually come up with Actions, useActionState, useFormStatus, and useOptimistic, each cover a different part of that workflow. None of them is a separate way to submit a form.
What an Action is
The React Team’s release post for React 19, published December 5, 2024, describes the common case this way: “A common use case in React apps is to perform a data mutation and then update state in response.” React v19 That sentence is the whole definition. An Action is the function that does the mutation and returns the state the UI should show afterward.
Before React 19, the usual pattern was to write an event handler, set a loading flag by hand, call the server, and then set the result. React 19 lets you pass a function directly to the action prop of a <form> (or to formAction on a button or input). React then tracks the pending period for you, and when a form Action succeeds, React resets uncontrolled inputs in that form.
Do these 3 things before closing this tab:
1Clear out junk files and repair common Windows errors2Fix the driver behind crashes, sound loss and screen glitches3Repair Windows errors before they cause bigger problemsA minimal Action is an ordinary async function that receives the form data:
#1 Best Overall
async function saveName(formData) {
const name = formData.get("name");
await updateProfileName(name); // your own mutation
}
function ProfileForm() {
return (
<form action={saveName}>
<input name="name" />
<button type="submit">Save</button>
</form>
);
}
How an Action moves through React
- The user submits the form, or triggers an element with
formAction. - React runs the Action inside a transition, which is why the UI can keep responding while the mutation is in flight.
- While the Action is pending, status values such as
isPending(fromuseActionState) andpending(fromuseFormStatus) aretrue. - Optimistic state set during the Action appears immediately. React returns to the base state when the operation settles.
- The Action’s result becomes the new state, and the form resets if the Action succeeded.
The three hooks, and what each one reads
The hooks are best compared by three questions: what state the hook represents, where it reads its context, and how long its value is meant to last.
| Hook | What it represents | What it returns | Where it reads from | How long the value lasts |
|---|---|---|---|---|
useActionState |
The state returned by an Action | Current state, a dispatcher (the form action), and isPending |
The Action passed to the hook; the Action receives the previous state and the submitted payload | Until the next Action result replaces it |
useFormStatus |
The submission status of a form | Status including pending and submitted data |
The parent <form> that renders the component |
For the submission lifecycle |
useOptimistic |
An anticipated state shown during an Action | Optimistic state and a setter | The base state you pass in, plus an optional reducer | For the optimistic interval; the base state takes over when the operation settles |
Sources: useActionState, useFormStatus, useOptimistic.
useActionState: state returned by an Action
useActionState is the hook that owns the Action’s result. It takes an Action and an initial state, and returns the current state, a form action to attach to a <form>, and an isPending flag. Because the Action receives the previous state, it can build up results across submissions, such as a running error message or a count.
Free tools Windows power users keep installed
One-click scans. No signup required.
It is not only a form-status hook. Use it whenever the component needs to render something that depends on what the last Action returned, not just whether a submission is in progress. The hook can also accept an optional permalink, which is used for progressive enhancement when the Action is a Server Function.
import { useActionState } from "react";
async function addItem(previousState, formData) {
const item = formData.get("item");
const ok = await saveItem(item); // your own mutation
if (!ok) return { error: "Could not save " + item, message: null };
return { error: null, message: "Added " + item };
}
function AddItemForm() {
const [state, formAction, isPending] = useActionState(addItem, {
error: null,
message: null,
});
return (
<form action={formAction}>
<input name="item" />
<button type="submit" disabled={isPending}>Add</button>
{state.error && <p>{state.error}</p>}
{state.message && <p>{state.message}</p>}
</form>
);
}
useFormStatus: status for a component inside a form
useFormStatus reads the status of the form that contains the component calling it. This matters for design-system components. A submit button buried in a shared Button component can disable itself while the form is submitting, without the form passing a pending prop down through every layer.
The hook has one rule that trips people up: it reads its parent form. Calling it in the same component that renders the <form> does not give you that form’s status. Move the call into a child component.
import { useFormStatus } from "react-dom";
function SubmitButton() {
const { pending } = useFormStatus();
return (
<button type="submit" disabled={pending}>
{pending ? "Saving…" : "Save"}
</button>
);
}
useOptimistic: showing the expected result early
useOptimistic changes what the UI shows while an Action is running. You give it the base state, which is the real data, and it returns an optimistic copy plus a setter. You call the setter inside an Action, and React shows the optimistic copy until the operation settles, then falls back to the base state.
The hook does not save anything. Persistence still belongs to your mutation. If the server call fails, the UI returns to the base state, so the code that performs the mutation must still handle errors and update the base data when the call succeeds.
import { useOptimistic } from "react";
function Messages({ messages, sendMessage }) {
const [optimisticMessages, addOptimisticMessage] = useOptimistic(
messages,
(current, newText) => [...current, { text: newText, sending: true }]
);
async function formAction(formData) {
const text = formData.get("text");
addOptimisticMessage(text); // called inside the Action
await sendMessage(text); // your own mutation
}
return (
<form action={formAction}>
{optimisticMessages.map((m, i) => (
<p key={i}>{m.text}{m.sending ? " (sending)" : ""}</p>
))}
<input name="text" />
<button type="submit">Send</button>
</form>
);
}
Server Functions and Server Actions
React’s documentation separates two terms. A Server Function is a function marked to run on the server and be called from client code. A Server Action is a Server Function that is passed to an action prop or called inside an Action. Not every Server Function is a Server Action. The distinction matters when you read older posts, because the two words are often used loosely. See Server Functions for the exact conditions.
Naming changes from earlier releases
useActionState was called useFormState in earlier Canary releases. Use the current name in new code and when writing explanations. Mention the older name only when a reader is looking at code or a tutorial that still uses it.
Rank #3
Common mistakes
- Expecting
useFormStatusto work in the form’s own component. It reads the parent form, so put it in a child component rendered inside the<form>. - Calling the
useOptimisticsetter outside an Action. The optimistic update is meant to run inside an Action or transition. Outside one, it will not behave as a temporary state that reverts. - Treating optimistic state as saved data. When the operation fails, the base state returns. Keep the base data in sync when the mutation succeeds.
- Using
useActionStateonly for pending spinners. Its main value is the returned state. If you only need submission status in a nested component,useFormStatusis the simpler fit.
Choosing a hook
Start with what the component has to show. If it needs the result of the last Action, use useActionState. If a nested control needs to know whether its form is submitting, use useFormStatus. If the interface should show the likely outcome before the server responds, wrap the base data with useOptimistic. Many real forms use all three: useActionState drives the form, a child button reads useFormStatus, and a list inside the form uses useOptimistic for items being sent.
The React 19 release post is the reference for the Action model itself, and the hook pages linked above give the full signatures and edge cases.
Full reference for the three hooks is in the React documentation linked above. Use them as complements in one workflow, rather than as alternatives to choose among.
Full reference for the three hooks is in the React documentation linked above.
Full reference for the three hooks is in the React documentation linked above.
Rank #4
Full reference for the three hooks is in the React documentation linked above.
Full reference for the three hooks is in the React documentation linked above.
Full reference for the three hooks is in the React documentation linked above.
Full reference for the three hooks is in the React documentation linked above.
Full reference for the three hooks is in the React documentation linked above.
Best Value
Full reference for the three hooks is in the React documentation linked above.
Full reference for the three hooks is in the React documentation linked above.
Full reference for the three hooks is in the React documentation linked above.
The Tool Desk
Outbyte PC Repair FREERepair Windows errors before they cause bigger problemsFix Now →Outbyte Driver Updater FREEFix the driver behind crashes, sound loss and screen glitchesFind Drivers →Full reference for the three hooks is in the React documentation linked above.
Full reference for the three hooks is in the React documentation linked above.
Quick Recap
Product prices and availability are accurate as of the date/time indicated and are subject to change. Any price and availability information displayed on Amazon at the time of purchase will apply.

