0

when I check the console I get :

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

I'm using "react-dom": "^18.0.0", "react-router-dom": "^6.3.0". But then when I use createRoot in my index.js I don't have the error but some functionnalities are not working (such as this issue that I get here)

What I have:

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

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

What I tried :

import { StrictMode } from "react";
import { createRoot } from "react-dom/client";
import App from "./App";

const rootElement = document.getElementById("root");
const root = createRoot(rootElement);

root.render(
  <StrictMode>
    <App />
  </StrictMode>
);
Zokulko
  • 211
  • 4
  • 25

1 Answers1

-1
import ReactDOM from "react-dom/client";
const root = ReactDOM.createRoot(document.getElementbyId("root")
root.render(<App/>);

you never imported reactDOM.

  • Hi, when I'm on my react page I get this error :`index.js:63 Unexpected text node: . A text node cannot be a child of a ` And my index.js is the same as yours. – Zokulko May 15 '22 at 15:32
  • @Zokulko can you post your current index.js so I can take a look at it? – Eleazar Udo May 16 '22 at 13:07
  • My index is this one : `import "./index.css"; import App from "./App"; import React from "react"; import ReactDOM from "react-dom"; ReactDOM.render( , document.getElementById("root") );` I have a warning that it's not longer supported in React18, and when I change by your solution I haven't the warning 'not supported...' but I have some functionnalities in my app that doesn't work... see here the [issue](https://stackoverflow.com/questions/72058578/dropdowns-are-not-working-using-react-draft-wysiwyg-in-react-js) – Zokulko May 16 '22 at 13:51
  • @Zokulko you should import ReactDOM from "react-dom/client" not from "react-dom" – Eleazar Udo May 18 '22 at 17:06
  • when I do that then I got a blank page – Zokulko May 19 '22 at 23:04