DEV Community

Utkrista KC
Utkrista KC

Posted on

Solved Warning: ReactDOM.render is no longer supported in React 18. Use createRoot instead.

Image description

We get this warning as React 18 introduces a new root API
for managing roots.

For instance, this is the code instance in your project which has ReactDOM.render specified.

import React from "react";
import ReactDOM from "react-dom";
import App from "./App";
import "./index.css";

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

Enter fullscreen mode Exit fullscreen mode

To remove this warning, simply follow this:

import React from "react";
import { createRoot } from "react-dom/client";
import App from "./App";
import "./index.css";

const container = document.getElementById("root");
const root = createRoot(container);
root.render(<App />);

Enter fullscreen mode Exit fullscreen mode

Top comments (0)