React Foundations ยท Robustness & DX

Upgrading to React 19

The React 19 upgrade

Upgrading to React 19

You upgrade a project to React 19 and hit a handful of small surprises. React 19 is mostly additive, but it removes some long-deprecated APIs and promotes several workarounds to built-ins. Knowing the differences saves an afternoon.

forwardRef is no longer needed. A function component receives ref as a normal prop, so <Input ref={ref} /> works:

function Input({ ref, ...props }) {
  return <input ref={ref} {...props} />;
}

forwardRef still works and is not removed yet, but new code should take the prop directly.

<Context> is its own provider. You can render <ThemeContext value="dark"> instead of <ThemeContext.Provider value="dark">.

Mounting changed. ReactDOM.render and ReactDOM.hydrate are gone. Use createRoot and hydrateRoot from react-dom/client, the recommended API since React 18.

Legacy props are gone on function components. propTypes and defaultProps are removed โ€” use TypeScript and default parameters instead. The ReactDOM.render-era string refs are removed too.

Renames in the Actions API. useFormState is now useActionState, from react. useFormStatus moved to react-dom.

New in 19: document metadata (<title>, <meta>) rendered from a component is hoisted to <head>, ref callbacks may return a cleanup function, and errors are reported through onUncaughtError / onCaughtError / onRecoverableError.

You are about to answer a short quiz on the React 19 upgrade.

  1. In React 19, a function component can receive ref as a normal prop.
  2. ReactDOM.render is still the recommended way to mount a React 19 app.
  3. The React 19 mount API createRoot is imported from ___-dom/client.
  4. defaultProps is still supported on function components in React 19.
  5. The React 19 hook useActionState was previously called ___.