0

I'm using react@18 in "standalone" mode and get a warning using createRoot.

The reactjs code is inlined in the HTML file, in a script section - . The HTML header in the current HTML file includes these sources:

<script src="https://unpkg.com/react@18/umd/react.development.js"></script>
<script src="https://unpkg.com/react-dom@18/umd/react-dom.development.js"></script>
<script src="https://unpkg.com/babel-standalone@6.26.0/babel.js"></script>

I attempt to access createRoot() like this:

const root = ReactDOM.createRoot(container);

That line leads to this error -> Warning: You are importing createRoot from "react-dom" which is not supported. You should instead import it from "react-dom/client".

What is the correct way to import this from "react-dom/client"? What is the correct way to do this standalone - <script src=" ... "></script> to use?

Gabriele Petrioli
  • 191,379
  • 34
  • 261
  • 317
  • Does this answer your question? [Stand-alone React 18 page warning: importing createRoot from "react-dom"](https://stackoverflow.com/questions/71957303/stand-alone-react-18-page-warning-importing-createroot-from-react-dom) – Gabriele Petrioli Apr 25 '22 at 13:45
  • This might Help https://github.com/facebook/react/pull/24274 This is main issue for react client dom error – Tushar Mistry Apr 25 '22 at 13:59

1 Answers1

0

What is the correct way to import this from "react-dom/client"?

You are using the correct way.


Unfortunately there's a bug inside the UMD build thats causing the error.

A fix has already been merged, but UNPKG does not yet serve the version which has the fix included.


For now: just ignore the warning.

0stone0
  • 34,288
  • 4
  • 39
  • 64