React 19: what changed and what to use first

Form actions, useActionState, useOptimistic and use, with examples, what was removed and how to upgrade.

React 19 is less about new ways to draw an interface and more about removing code you used to write by hand. Forms, pending states, optimistic updates and data loading all get built-in support. This is a practical tour of what changed, with the parts worth adopting first.

Actions: forms without the boilerplate

Submitting a form used to mean an onSubmit handler, a loading flag, an error state and a try/catch. In React 19 a form can take a function as its action. React runs it, tracks whether it is pending, and resets the form when it succeeds.

The useActionState hook wraps such a function and gives back its latest result, the action to pass to the form, and a pending flag:

import { useActionState } from 'react'

function Signup() {
  const [error, submit, pending] = useActionState(async (previous, formData) => {
    const result = await createAccount(formData.get('email'))
    return result.ok ? null : result.message
  }, null)

  return (
    <form action={submit}>
      <input name="email" type="email" required />
      <button disabled={pending}>Create account</button>
      {error && <p role="alert">{error}</p>}
    </form>
  )
}

A button deep inside a form can read the form’s state with useFormStatus, so a shared submit button no longer needs the pending flag passed down to it.

useOptimistic: show the result before the server answers

Interfaces feel faster when they show the expected result immediately. useOptimistic holds a temporary value while an action is running and returns to the real value when it finishes, including when it fails.

const [shownLikes, addLike] = useOptimistic(
  likes,
  (current, extra) => current + extra,
)

async function like() {
  addLike(1)          // shown at once
  await saveLike(id)  // the real value replaces it when this settles
}

use: read a promise or a context while rendering

The new use function reads a value from a promise or a context. With a promise, the component suspends until the value is ready, and the nearest Suspense boundary shows its fallback. Unlike hooks, use may be called inside a condition or a loop.

function Comments({ commentsPromise }) {
  const comments = use(commentsPromise)
  return comments.map((c) => <p key={c.id}>{c.text}</p>)
}

The promise should be created outside the component, for example by a framework’s loader or a cache, not afresh on every render.

Smaller changes you will notice every day

  • ref is an ordinary prop. A function component can accept ref directly, so forwardRef is no longer needed for new code.
  • A context can be rendered as a provider directly: <ThemeContext value={theme}>.
  • Title, meta and link tags written inside a component are moved into the document head by React.
  • Stylesheets and scripts declared in components are loaded once and in a sensible order, and there are functions to preload resources.
  • A ref callback can return a cleanup function.
  • Hydration errors show the difference between server and client output instead of a vague warning.
  • Custom elements receive properties correctly.

Server Components and Server Actions

Server Components render on the server and send no JavaScript for themselves to the browser. Server Actions let a client component call a function that runs on the server. Both are stable in React 19, but they need a framework that supports them, such as Next.js. In an application built with Vite and rendered entirely in the browser, you can use everything above without them.

What was removed

React 19 removes several APIs that had been deprecated for years. Check for these before upgrading:

  • ReactDOM.render and ReactDOM.hydrate. Use createRoot and hydrateRoot.
  • propTypes and defaultProps on function components. Use TypeScript and default parameter values.
  • String refs and the legacy context API.
  • react-test-renderer is deprecated in favour of React Testing Library.

The React Compiler is separate

The compiler that removes the need for most useMemo and useCallback calls is a build-time tool installed on its own. It is not part of the React 19 package, and React 19 does not require it. Treat it as a later, optional step.

How to upgrade

  • Move to the last React 18 release first. It prints warnings for everything React 19 removes.
  • Fix the warnings, then update react and react-dom together, along with their type packages.
  • Run the official codemods for the mechanical changes.
  • Check that your main libraries, such as the router, form and data libraries, support React 19.
  • Test forms, anything using refs, and server rendering if you have it.

What to adopt first

Start with form actions and useActionState in the next form you build; the saving in code is immediate. Stop writing forwardRef in new components. Add useOptimistic where a slow request makes an action feel sluggish. Leave working code alone: nothing in React 19 requires rewriting components that already behave correctly.