Warning: ReactDOM.render is no longer supported in React 18
- 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
- 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 />);