How to Update React
What you’ll build or solve
You’ll update a React project to a newer React version.
When this approach works best
This approach works best when:
Learn React on Mimo
- You need a newer React version for a library you want to use.
- You want security patches, bug fixes, or improvements from a newer release.
- You are upgrading a project after cloning it and want current dependencies.
- You maintain several apps and want them on the same React version.
This is a bad idea if your project depends on older libraries that do not support the React version you want. Check compatibility first, especially for major version jumps.
Prerequisites
- A React project with a
package.json - Node.js installed
- Your dev server runs successfully before the update
- You know your current version so you can confirm it changed
Check your current version:
npm list react--depth=0
If you use Yarn:
CSS
yarn list--pattern react
If you use pnpm:
pnpm list react
Step-by-step instructions
1) Install the updated version
Pick the option that matches your goal, then run it from the project root.
Option A: Update to the latest version (most common)
npm install react@latest react-dom@latest
If you use Yarn:
SQL
yarn add react@latest react-dom@latest
If you use pnpm:
SQL
pnpm add react@latest react-dom@latest
Option B: Update to a specific version
npm install react@18.3.1 react-dom@18.3.1
Use this when a dependency or team standard requires a specific version.
What to look for
- Update
reactandreact-domtogether. - Keep their major versions aligned.
- Restart your dev server after the install so it loads the updated packages.
- Confirm the installed version changed:
npm list react--depth=0
- If you upgraded across major versions, scan the release notes. Major upgrades can require code changes.
Examples you can copy
Example 1: Update to the latest React
cd my-react-app
npm install react@latest react-dom@latest
npm list react--depth=0
Use this when you want the newest stable release.
Example 2: Pin React to a specific version
npm install react@18.2.0 react-dom@18.2.0
Use this when a dependency or team standard requires a specific version.
Example 3: Update in a Vite project
SQL
pnpm add react@latest react-dom@latest
pnpm list react
The update command depends on the package manager, not on Vite vs Create React App.
Common mistakes and how to fix them
Mistake 1: Updating only react
What you might do:
CSS
npm install react@latest
Why it breaks:
react-dom can stay on an older major version, which may cause runtime issues.
Correct approach:
npm install react@latest react-dom@latest
Mistake 2: Running the install outside the project root
What you might do:
Run the update command in the wrong folder.
Why it breaks:
The package manager updates the nearest package.json, which might not be your React app.
Correct approach:
CSS
cd path/to/your-react-app
npm install react@latest react-dom@latest
Mistake 3: Expecting the running dev server to pick up the update
What you might do:
Keep the server running and refresh the browser.
Why it breaks:
The server process may still use packages already loaded in memory.
Correct approach:
Stop the server with Ctrl + C, then start it again:
npm run dev
Troubleshooting
If you see command not found: npm, install Node.js and restart your terminal.
If you see permission errors during install, avoid sudo. Fix your Node setup instead.
If npm list react shows multiple versions, try:
npm dedupe
If the app errors after a major update, pin back to the last working version:
npm install react@18.2.0 react-dom@18.2.0
If TypeScript or bundler errors appear after updating, delete and reinstall dependencies:
rm-rf node_modules
npm install
Quick recap
- Check your current version with
npm list react --depth=0. - Update React by installing
reactandreact-domtogether. - Use
@latestor a specific version number. - Restart your dev server after updating.
- Re-check the installed version to confirm the change.
Join 35M+ people learning for free on Mimo
4.8 out of 5 across 1M+ reviews
Check us out on Apple AppStore, Google Play Store, and Trustpilot