JIYIK CN >

Current Location:Home > Learning > WEB FRONT-END > React >

How to update your React version

Author:JIYIK Last Updated:2025/03/16 Views:

To update our version of React, we need to npm install react@latest react-dom@latestinstall the latest version of react and react-dom packages by running . If you use create-react-appreact-scripts, also update your version.

Open a terminal in the root directory of your project (where your package.json file is located) and run the following command:

# 👇️ 使用 NPM
$ npm install react@latest react-dom@latest

# 👇️ 仅当使用 TypeScript
$ npm install --save-dev @types/react@latest @types/react-dom@latest

# ------------------------------

# 👇️ 使用 YARN
$ yarn add react@latest react-dom@latest

# 👇️ 仅当使用 TypeScript
$ yarn add @types/react@latest @types/react-dom@latest --dev

This command will update the versions of react related packages.

If you get an error, try --forcerunning the command with the -n flag, npm install react@latest --forcee.g.

If you use create-react-appreact-scripts, also update the version of the react-scripts package.

# 👇️ 使用 npm
$ npm install react-scripts

# ----------------------------------------------

# 👇️ 使用 yarn
$ yarn add react-scripts

If you get an error, --forcerun the command with the -o flag or delete your node_modules and package-lock.json (not package.json) files and rerun npm install.

# 👇️ 删除 node_modules 和 package-lock.json
$ rm -rf node_modules
$ rm -f package-lock.json

# 👇️ 清除 npm 缓存
$ npm cache clean --force

$ npm install

Make sure your index.js file uses the new createRoot API.

import {StrictMode} from 'react';
import {createRoot} from 'react-dom/client';

import App from './App';

// 👇️ 确保使用 public/index.html 文件中的正确根元素 ID
const rootElement = document.getElementById('root');
const root = createRoot(rootElement);

root.render(
  <StrictMode>
    <App />
  </StrictMode>,
);

createRoot()The method takes the root element as a parameter and creates a React root.

We can also update the version of any react related package, such as react-testing-librarynpm install some-package@latest --force by running the command .

For reprinting, please send an email to 1244347461@qq.com for approval. After obtaining the author's consent, kindly include the source as a link.

Article URL:

Related Articles

Updating PHP 7.x to 7.4 on CentOS

Publish Date:2025/04/13 Views:131 Category:PHP

This article shows the steps to update the PHP version from 7.x version to 7.4 in CentOS. How to Update PHP from 7.X to 7.4 in CentOS Update operating system packages. yum update -y Check your PHP version in CentOS. php -v Prints a list of

Use of UPDATE JOIN in MySQL

Publish Date:2025/04/11 Views:85 Category:MySQL

This tutorial will explain how to use the statement in MySQL database UPDATE JOIN . We generally use joins to iterate over the rows in a particular table which may or may not have similar rows in other tables. We can UPDATE use JOIN the cla

Update Push Array in MongoDB

Publish Date:2025/04/10 Views:90 Category:MongoDB

This post will show you how to add elements to an array in MongoDB using various techniques. Pushing or appending elements to an array is very convenient for quickly appending lists by adding or moving objects in an existing MongoDB documen

Update Git clone

Publish Date:2025/04/03 Views:111 Category:Git

This article outlines the steps we can take to update our cloned repository in Git. Suppose we have a remote repository on GitHub that we forked and cloned on our local machine. How can we update our cloned repository with the original remo

Updating existing images with Docker Compose

Publish Date:2025/03/25 Views:153 Category:Docker

Docker containers are designed to be disposable and easily replaceable. Therefore, whenever the base image of a container receives an update, we should pull the updated image and start a new instance of the container. This article will disc

Updating YUM in Linux

Publish Date:2025/03/23 Views:150 Category:OPERATING SYSTEM

This article will teach us how to update YUM in Linux and how to install, update, remove, find and manage packages on a Linux system. We have also seen the difference yum update between and in Linux yum upgrade . yum update command in Linux

How to avoid cross-origin (CORS) issues in React/Next.js

Publish Date:2025/03/17 Views:170 Category:NETWORK

In this article, we will introduce how to avoid cross-origin (CORS) issues in React/Next.js. Cross-origin resource sharing (CORS) is a protocol that defines how web requests should be handled when crossing different URLs.

React Tutorial - Transferring Props

Publish Date:2025/03/16 Views:188 Category:React

React transfers Props. Props are generated when components are encapsulated. Components expose some properties (Props) to the outside world to complete some functions.

React Tutorial: Props Anti-Pattern

Publish Date:2025/03/16 Views:187 Category:React

React's Props anti-pattern, using Props to generate state in getInitialState is an anti-pattern - Anti-Pattern.

Scan to Read All Tech Tutorials

Social Media
  • https://www.github.com/onmpw
  • qq:1244347461

Recommended

Tags

Scan the Code
Easier Access Tutorial