Every form submission in React used to look like this:
const [data, setData] = useState(null)
const [loading, setLoading] = useState(false)
const [error, setError] = useState(null)
async function handleSubmit(e) {
e.preventDefault()
setLoading(true)
try {
const result = await submitToServer(formData)
setData(result)
} catch (err) {
setError(err.message)
} finally {
setLoading(false)
}
}
Three useState calls. A try/catch/finally. Manual loading and error flags. And that's without optimistic updates β add those and you're looking at another 20 lines of snapshot/revert logic.
React 19 ships two hooks that delete most of this.
useActionState β form lifecycle in one hook
const [error, submitAction, isPending] = useActionState(
async (prevState, formData) => {
const res = await fetch('/api/submit', {
method: 'POST',
body: formData,
})
if (!res.ok) return 'Something went wrong'
return null
},
null
)
return (
<form action={submitAction}>
<input name="email" type="email" />
<button disabled={isPending}>
{isPending ? 'Sending...' : 'Submit'}
</button>
{error && <p>{error}</p>}
</form>
)
isPending is automatic. Error state is the return value of your action. No useState, no try/catch wrappers, no finally.
useOptimistic β instant UI without manual rollback
The old way of doing a like button:
// snapshot β update β revert on error = ~30 lines
The React 19 way:
const [optimisticLikes, addOptimisticLike] = useOptimistic(
likes,
(current, increment) => current + increment
)
async function handleLike() {
addOptimisticLike(1) // instant UI
await likePost(postId) // server confirms
}
return <button onClick={handleLike}>β€οΈ {optimisticLikes}</button>
That's it. If the server call fails, React automatically reverts to the real value β no manual rollback code needed. The optimistic state is just a temporary layer that disappears when the action settles.
One important gotcha
addOptimistic must be called before any await in your action. React's transition system only captures optimistic updates issued synchronously before the first suspension point. Call it after an await and the update won't show up.
// β
correct
addOptimisticLike(1)
await likePost(postId)
// β won't work
await someOtherThing()
addOptimisticLike(1)
When to still use React Query / SWR
These hooks are for component-local action state. If your mutation needs to invalidate a cache shared across multiple components, you still want React Query or similar. But for the submit-and-respond pattern that covers the majority of forms and mutations in a typical app β these built-ins are now the right default.
United States
NORTH AMERICA
Related News
π I Built a Dropshipping Automation Pipeline β Here's What I Learned (and What I'd Do Differently)
10h ago
How I Cut My LLM API Bill by 40x: A Freelancer's Migration Story
10h ago

Mattress Firm Coupons: Save up to $600
3h ago
Google Ordered to Pay $2 Billion For Anti-Competitive Practices By Swedish Court
20h ago
The Censorship Wall: Why Every AI Companion App Ends Up Filtering You
20h ago