I changed one line in package.json, from React 18 to React 19. The app started. No red errors. Then I noticed every "Save" button on the page was blank.
The culprit was this:
function Button({ label }) {
return <button>{label}</button>;
}
Button.defaultProps = { label: "Save" }; // ignored in React 19
React 19 removes a few old APIs that had been deprecated for years, and adds new ones that make everyday code shorter. Most apps need small fixes, not a rewrite. Here's what actually matters, and the two changes worth learning properly.
Will this affect me? A 30-second checklist
Search your code for these. Each "yes" is something to fix:
- [ ]
ReactDOM.render(orReactDOM.hydrate( - [ ]
.defaultProps =on a function component - [ ]
.propTypes =(React no longer checks them) - [ ]
ref="something"with a string (string refs) - [ ]
contextTypesorgetChildContext(legacy context) - [ ]
import { act } from "react-dom/test-utils" - [ ]
react-test-renderer/shallow - [ ] TypeScript ref callbacks written like
ref={el => (box = el)}
All boxes empty? Your upgrade will probably be boring. That's the good kind.
Upgrade the safe way: 18.3 first
Don't jump straight to 19. React 18.3 is the same as 18.2, plus warnings for everything React 19 removes. So:
- Install
react@18.3andreact-dom@18.3. - Open your app and tests, and fix every warning in the console.
- Now install React 19.
Then let the official codemods do the boring edits for you:
npx codemod@latest react/19/migration-recipe
It rewrites ReactDOM.render, string refs, the act import and more. If you use TypeScript, also run npx types-react-codemod@latest preset-19 ./src. Always read the diff before you commit it.
What got removed, and what to use instead
| Old way (React 18) | React 19 | Use instead |
|---|---|---|
ReactDOM.render, ReactDOM.hydrate
|
Removed |
createRoot, hydrateRoot from react-dom/client
|
defaultProps on function components |
Removed | Default parameters: { label = "Save" }
|
propTypes checks |
Silently skipped | TypeScript |
String refs (ref="input") |
Removed |
useRef or a ref callback |
Legacy context (contextTypes) |
Removed |
createContext + useContext
|
act from react-dom/test-utils
|
Moved | import { act } from "react" |
react-test-renderer/shallow |
Removed | React Testing Library |
The fix for my blank buttons was one line:
function Button({ label = "Save" }) {
return <button>{label}</button>;
}
Class components still support defaultProps. Only function components lost it.
Two quieter changes that can surprise you
Errors are no longer thrown twice. In React 18, an error during render was re-thrown, which is why you often saw it logged twice in development. In React 19, errors that no error boundary catches go to window.reportError, and caught ones go to console.error. If you send errors to a logging service, use the new root options:
createRoot(el, {
onUncaughtError: (error, info) => logError(error, info.componentStack),
onCaughtError: (error) => logError(error),
});
Ref callbacks can return a cleanup function. React calls it when the element goes away, just like a useEffect cleanup. Nice! But it means React now cares what your ref callback returns. In TypeScript, this line is now an error:
<div ref={el => (box = el)} /> // returns el: TypeScript complains
<div ref={el => { box = el; }} /> // returns nothing: fine
The arrow without braces returns the element, and React would try to treat that as a cleanup. Add braces and the problem is gone.
See the two big wins
The rest of React 19 is mostly about writing less code. Two changes do that more than any other. Watch them happen:
Deep dive 1: ref is just a prop now
Say you build your own Input and the parent wants to focus it. In React 18, ref was special. It never reached your component as a prop, so you had to wrap everything in forwardRef:
import { forwardRef } from "react";
const Input = forwardRef(function Input(props, ref) {
return <input ref={ref} {...props} />;
});
In React 19, a function component receives ref like any other prop:
function Input({ ref, ...props }) {
return <input ref={ref} {...props} />;
}
That's it. No wrapper, no import, no strange two-argument function. The parent code doesn't change at all:
const inputRef = useRef(null);
<Input ref={inputRef} />;
This sounds small, but think about a design system with 40 components wrapped in forwardRef. All of that ceremony just disappears. forwardRef still works in React 19, so you can remove it slowly, one component at a time.
💡 This is one of the hands-on lessons in the React course on DevTrail. You upgrade a small app to React 19 yourself and watch each change work, right in your browser, with nothing to install.
A cousin of this change: a context is now its own provider. You can write <ThemeContext value="dark"> instead of <ThemeContext.Provider value="dark">. The old way still works too.
Deep dive 2: form Actions and useActionState
Here's a form most of us have written many times. A newsletter box that shows "Joining..." while it waits, and an error if it fails:
function Subscribe() {
const [error, setError] = useState(null);
const [isPending, setIsPending] = useState(false);
async function handleSubmit(e) {
e.preventDefault();
setIsPending(true);
const form = new FormData(e.target);
setError(await subscribe(form)); // returns an error message, or null
setIsPending(false);
}
return (
<form onSubmit={handleSubmit}>
<input name="email" />
<button disabled={isPending}>Join</button>
{error && <p>{error}</p>}
</form>
);
}
Two pieces of state, a handler and preventDefault. All of it is plumbing.
React 19 lets you pass a function to <form action>. React calls it with the form data when the user submits. That function is called an Action. And useActionState wraps an Action and tracks two things for you: what it returned last, and whether it's still running.
import { useActionState } from "react";
function Subscribe() {
const [error, submitAction, isPending] = useActionState(
async (prevError, form) => {
return await subscribe(form); // whatever you return becomes `error`
},
null // starting value
);
return (
<form action={submitAction}>
<input name="email" />
<button disabled={isPending}>Join</button>
{error && <p>{error}</p>}
</form>
);
}
Read the hook's result like a sentence: "the last result, the thing to call, and am I busy?" No useState, no handler, no preventDefault. As a bonus, React clears the form's fields after the action succeeds.
Need the pending state inside a child, like a reusable <SubmitButton>? useFormStatus from react-dom reads it from the nearest parent <form>, so you don't have to pass props down.
The mistake almost everyone makes
The function you give to useActionState gets two arguments, and the form data is the second one:
// ❌ `form` is actually the previous state here
useActionState(async (form) => subscribe(form), null);
// ✅ previous state first, form data second
useActionState(async (prev, form) => subscribe(form), null);
The first argument is the previous result (the null you started with, then whatever you returned). It's easy to miss because a plain <form action={fn}> does get the form data first. If form.get is "not a function", this is why.
What you'd learn next
You now know what breaks in React 19 and two patterns that make your code shorter. There's a lot more in the box:
- ✅ The React 19 changes that break apps, and how to fix them (this post)
- ✅
refas a prop and form Actions withuseActionState(this post) - 🔒
useOptimistic: show the result before the server answers - 🔒
use(): read a promise or context, even inside anif - 🔒
useTransitionanduseDeferredValue: keep typing smooth while heavy work runs - 🔒 Suspense for data, and how concurrent rendering really works
- 🔒 How React renders: reconciliation, Fiber and why components re-render
- 🔒 Server Components and Server Functions: what runs where
- 🔒 Performance: memo,
useMemo,useCallbackand when not to use them - 🔒 Testing React components the right way
Preparing for interviews? React Interview Prep covers React 19 questions too.
🚀 Go from zero to hero with React
This post covered a slice of module 15 of 17. The full React: Basic to Advanced course on DevTrail goes from your first component to hooks, rendering internals, performance, React 19 and Server Components: 17 modules and 90 hands-on lessons.
Every lesson has code you run and check right in your browser. No setup, no "works on my machine".
Module 1 is free. Start the React course →

Top comments (0)