Curriculum
Course: React
Login

Curriculum

React

Text lesson

React Upgrade 18

To upgrade an existing React application to version 18, follow two simple steps. If you’re already using the latest version of create-react-app with React 18, you can skip this part.

Step 1: Install React 18

To install the latest version, run the following command from your project folder in the terminal:

npm i react@latest react-dom@latest

Step 2: Use the new root API

To utilize React 18’s concurrent features, you’ll need to use the new root API for client rendering.

// Before
import ReactDOM from 'react-dom';
ReactDOM
.render(<App />, document.getElementById('root'));
// After
import ReactDOM from 'react-dom/client';
const root = ReactDOM.createRoot(document.getElementById('root'));
root.render(<App />);