HiveBrain v1.2.0
Get Started
← Back to all entries
patternjavascriptreactCritical

Deprecation notice: ReactDOM.render is no longer supported in React 18

Submitted by: @import:stackoverflow-api··
0
Viewed 0 times
supportedrenderreactdomreactnoticedeprecationlonger

Problem

I get this error every time I create a new React app:

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. Learn more: https://reactjs.org/link/switch-to-createroot

How can I fix it?

I created my React app using:
npx create-react-app my-app

Solution

In your file index.js, change to:
import React from "react";
import ReactDOM from "react-dom/client";
import "./index.css";
import App from "./App";
import reportWebVitals from "./reportWebVitals";

const root = ReactDOM.createRoot(document.getElementById("root"));
root.render(



);

reportWebVitals();

For TypeScript

Credit from comment section below answer: Kibonge Murphy
import React from "react";
import ReactDOM from "react-dom/client";
import "./index.css";
import App from "./App";
import reportWebVitals from "./reportWebVitals";

const root = ReactDOM.createRoot(document.getElementById("root") as HTMLElement);
root.render(



);

reportWebVitals();

Context

Stack Overflow Q#71668256, score: 434

Revisions (0)

No revisions yet.