Courses / React 19: From Components to Production / Chapter 7
Module 3 · Routing and React 19 · Chapter 7 of 30
New in React 19: Actions, use, Optimistic UI and ref as a Prop
Builds on State and Effects: useState, Events, useEffect and Cleanup. Next up: Advanced Hooks: Refs, Reducers, Context, Layout Effects and Custom Hooks.
Part 1 · Actions: async work in transitions
What an Action is
A wedding RSVP page is mostly one form: a guest picks attending or not, and the page must show progress, handle failure and respond quickly. React 19 added tools for that whole loop, and this chapter follows them in the order a form uses them.
Before React 19, every async update needed hand-written bookkeeping: a loading flag set to true, a try and catch, a flag set to false again, an error state. An Action is React's name for an async function that runs inside a transition, so that React does that bookkeeping for you. A transition is an update React treats as non-urgent, which can be interrupted, and which keeps the current screen on display while it works.
You start an Action with startTransition or with the function returned by useTransition, and you pass it an async function. While the function runs, isPending is true. If the function returned by useTransition throws, React sends the error to the nearest error boundary. For the standalone startTransition, React reports the error with reportError instead, as a later chapter shows. State updates made inside it are batched, and the screen changes when they commit.
| Before React 19 |
|---|