Sitemap
JavaScript in Plain English

New JavaScript and Web Development content every day. Follow to join our 3.5M+ monthly readers.

Follow publication

Member-only story

useActionState — a cleaner way to handle action state in React (2025)

4 min readMay 26, 2025

--

isPending === true — but your UI is at peace.

useState is wonderful for local values, yet once you add loading spinners, success banners and error messages, components fill up with little states. useActionState lets me gather all those “results of one action” in a single structure and gives a built-in flag that tells me whether the action is still running. As a result:

  • far less boilerplate;
  • easy to disable controls while a request is pending;
  • success and error handling live in one place;
  • the UI stays responsive even before JavaScript is fully loaded if you rely on server components.

Anatomy of the hook

const [state, runAction, isPending] = useActionState(
async (prevState, formData) => { /* … */ },
initialState,
permalink? // optional URL for “no-JS yet” scenarios
);
  • state — whatever data your action returns.
  • runAction — the function you pass to formAction or call yourself.
  • isPending — automatically switches to true while the promise is in flight.

--

--

JavaScript in Plain English
JavaScript in Plain English

Published in JavaScript in Plain English

New JavaScript and Web Development content every day. Follow to join our 3.5M+ monthly readers.

Aleksei Aleinikov
Aleksei Aleinikov

Written by Aleksei Aleinikov

Insights in AI, Python, JavaScript, TypeScript, Go, React & Next.js. Sharing IT news, Data and DevOps tips & Cloud Solutions. Follow for deep dives into Tech!