Your Web News in One Place

Help Webnuz

Referal links:

Sign up for GreenGeeks web hosting
April 16, 2022 02:59 pm GMT

How to upgrade to React 18

Install React 18 and React DOM from npm or yarn, like this:

npm install react react-dom

Then, you'll want to use createRoot **instead of **render.

In your index.js, update ReactDOM.render to ReactDOM.createRoot to create a root, and render your app using root

Here's what it would look like in React 17:

import ReactDOM from 'react-dom';import App from 'App';const container = document.getElementById('app');ReactDOM.render(<App />, container);

And here's what it looks like in React 18:

import ReactDOM from 'react-dom';import App from 'App';const container = document.getElementById('app');// create a rootconst root = ReactDOM.createRoot(container);//render app to rootroot.render(<App />);

And you are now upgraded to React 18! enjoy!


Original Link: https://dev.to/adarshgoyal/how-to-upgrade-to-react-18-3dhi

Share this article:    Share on Facebook
View Full Article

Dev To

An online community for sharing and discovering great ideas, having debates, and making friends

More About this Source Visit Dev To