ReactDOM.render is no longer supported in React 18

If you are using ReactDOM.render() in your React 18 app, you will definitely see the below issue.

ReactDOM.render is no longer supported in React 18

The reason is ReactDOM.render is no longer supported in React 18.

Earlier, we used to render the component in below way

ReactDOM.render(<NavBar />, document.getElementById('root'))

If we are using React 18, we should start using createRoot() instead of render()

Example

ReactDOM.createRoot(document.getElementById('root')).render(<NavBar />)

The render() method of the react-dom package is considered legacy starting react-dom version 18.

The method is replaced with the createRoot() method that is exported from react-dom/client.

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

Happy Coding!

Advertisement

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s