Upgrading React from 18 to 19
Key changes in React 19
refis now passed as a normal prop to function components;forwardRefis no longer required and is deprecated for new code.- Actions and the
useActionState,useOptimistic, andusehooks are stable. defaultPropsfor function components is removed (it was deprecated in 18.3).- Legacy context types and string refs (long deprecated) are gone.
- The React Compiler is optional tooling that can reduce manual memoization; it is not required for the upgrade.
Migration steps
Step 1: Update packages
npm install react@19 react-dom@19
Step 2: Apply the official codemods
The React team ships codemods that rewrite most mechanical changes:
npx types-react-codemod@latest preset-19-from-18
Step 3: Fix remaining manual items
- Replace
forwardRefwrappers with plain props. - Move
defaultPropson function components to normal parameters. - Search for string
refusage and module-levelcontextTypes.
Step 4: Test
npm test
npm run build
Compatibility checklist
- Third-party component libraries must declare React 19 support; most major ones released updates.
- TypeScript users need the newest
@types/reactand@types/react-dom. - Hydration errors are stricter; fix them as they surface rather than muting warnings.