Upgrading an existing React application to version 18 takes only two steps.
If you are already using the most recent version of create-react-app, which runs React version 18, you can skip this part.
To install the newest version, run the following command from your project folder in the terminal:
npm i react@latest react-dom@latest
To take advantage of React 18’s concurrent features, use the new root API for client rendering.
// Before
import ReactDOM from 'react-dom';
ReactDOM.render( , document.getElementById('root'));
// After
import ReactDOM from 'react-dom/client';
const root = ReactDOM.createRoot(document.getElementById('root'));
root.render( );
Your application will function without utilizing the new root API. If you continue to use ReactDOM.render, your application will behave as React 17.
CodingAsk.com is designed for learning and practice. Examples may be made simpler to aid understanding. Tutorials, references, and examples are regularly checked for mistakes, but we cannot guarantee complete accuracy. By using CodingAsk.com, you agree to our terms of use, cookie, and privacy policy.
Copyright 2010-2024 by Refsnes Data. All Rights Reserved.