How to upgrade npm packages in react ?

To upgrade npm packages in a React project, follow these steps:

  1. Open the terminal or command prompt in the root directory of your React project.

  2. Use the following command to see the current versions of all the packages installed in your project:

npm outdated
  1. Identify the packages you want to upgrade and note down their package names and the latest version numbers.

  2. Use the following command to upgrade a specific package to its latest version:

npm install <package-name>@latest

Replace <package-name> with the name of the package you want to upgrade.

For example, to upgrade the "react" package to the latest version, use the following command:

npm install react@latest
  1. Repeat step 4 for all the packages you want to upgrade.

  2. Once you have upgraded all the desired packages, use the following command to update the package.json file with the latest versions of the packages:

sqlCopy codenpm update
  1. Verify that the packages have been successfully upgraded by running the following command to see the updated versions of all the packages:
npm list

Here's an example of how to upgrade the "react" and "react-dom" packages in a React project:

npm outdated

// Output:
// Package      Current  Wanted  Latest  Location
// react          17.0.2  17.0.2  17.0.3  my-react-app
// react-dom      17.0.2  17.0.2  17.0.3  my-react-app

npm install react@latest react-dom@latest
npm update
npm list