Warning: ReactDOM.render is no longer supported in React 18

Asked by: tomlance79
Date:
Viewed: 321
Answers: 1
  • 0

Hi,

I’m getting this error message in my console:

react-dom.development.js:86 Warning: ReactDOM.render is no longer supported in React 18. 
Use createRoot instead. Until you switch to the new API, your app will behave as if it's running React 17.

This is my index.js file:

import React from "react";
import ReactDOM from "react-dom";
import App from './components/App';
ReactDOM.render(<App />, document.getElementById('root'));

How do I fix this?

Answers

Answer by: jenniryan

Answered on: 21 Jul 2023

  • 0

Instead of this

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

Try this

import { createRoot } from 'react-dom/client';
const rootElement = document.getElementById('root');
const root = createRoot(rootElement);
root.render(<App />);

Please log in to post an answer!