2HAASStart a project
All posts

Tech News

React 19: Actions, the use API and Server Components

React 19 made forms and async state much simpler with Actions, useActionState and useOptimistic, added the use API and stabilized Server Components. A practical summary.

The 2HAAS team2 min read

React 19 became stable in December 2024. Its theme is removing code you used to write by hand: loading flags, error state, optimistic updates and wrappers such as forwardRef. This summary covers the changes that affect everyday work.

One correction to a common mix-up first: concurrent rendering arrived in React 18. React 19 builds on it.

Actions: async work without the boilerplate

Submitting a form used to need three pieces of state: the data, a pending flag and an error. React 19 lets you pass an async function straight to a form, and tracks the rest.

import { useActionState } from "react";

function NewsletterForm() {
  const [error, submit, isPending] = useActionState(async (previous, formData) => {
    const result = await subscribe(formData.get("email"));
    return result.ok ? null : result.message;
  }, null);

  return (
    <form action={submit}>
      <input type="email" name="email" required />
      <button disabled={isPending}>{isPending ? "Saving…" : "Subscribe"}</button>
      {error && <p role="alert">{error}</p>}
    </form>
  );
}

Three hooks work together here:

Hook What it gives you
useActionState The result of the last submission and a pending flag
useFormStatus The pending state of the parent form, for a shared submit button
useOptimistic A temporary value shown while the request is in flight

The use API

use reads a promise or a context during render. Unlike hooks, it can be called inside a condition or a loop.

function Comments({ commentsPromise }) {
  const comments = use(commentsPromise); // suspends until the data arrives
  return comments.map((c) => <p key={c.id}>{c.text}</p>);
}

Wrapped in <Suspense>, this replaces a good deal of useEffect data fetching.

Server Components and Server Functions

Server Components are stable in React 19. They render on the server and send no JavaScript of their own to the browser, which is what keeps large pages light. A component can read from a database directly, and only the interactive parts become client code.

Server Functions let a client component call a function that runs on the server, without you writing an API route for it. Both features need a framework that supports them, such as Next.js.

Smaller changes that add up

  • ref is a normal prop. Function components no longer need forwardRef.
  • Document metadata. <title>, <meta> and <link> tags rendered inside a component are moved to the document head.
  • Better hydration errors. A mismatch now shows a diff instead of a vague warning.
  • Custom elements. Web components work with props as expected.

Should you upgrade?

For most apps, yes. The React team published an upgrade guide and codemods that handle the mechanical changes. Move to the latest 18 release first, clear the warnings, then go to 19.

Automatic memoization is a separate tool. See React Compiler: memoization without useMemo.

Keep reading

  1. Tech News2 min read

    React Compiler: memoization without useMemo

    React Compiler memoizes components and values at build time, so most useMemo, useCallback and React.memo calls become unnecessary. What it does and how to adopt it.

  2. Tech News2 min read

    Angular Signals: fine-grained reactivity explained

    Signals give Angular a precise way to track state: when a value changes, only the views that read it update. How signal, computed and effect work, with examples.

  3. Tech News2 min read

    WebGPU: modern graphics and compute in the browser

    WebGPU gives web apps direct, modern access to the graphics card for 3D rendering and for general computation such as machine learning. What it is and where it stands.

Tell us what’s in the way.

A few lines is enough. You get a candid yes, a candid no, or a sharper question.

  • Working software in week four
  • A reply in one business day
  • Handover is the deliverable

Prefer email? [email protected]

The problem, who it is for, and what is in the way right now.

One business day to a real reply. No sales sequence, no call required.