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!