Warning: ReactDOM.render is no longer supported in React 18. Use createRoot instead
Warning: ReactDOM.render is no longer supported in React 18. Use createRoot instead
Through many examples, we will learn how to resolve the "Warning: ReactDOM.render is no longer supported in React 18. Use createRoot instead".
Warning: ReactDOM.render is no longer supported in React 18. Use createRoot instead.The error "ReactDOM.render is no longer supported in React 18. Use createRoot instead
" occurs because the ReactDOM.render method has been deprecated in react 18.
If you want to remove this error message from your react app you have to use react-dom/client
library and after that you can render the content in your react app using the render method on root node without any error message.
-
Render content using react-dom/client in react app
Move to index.js file under src directory and copy/paste code in it.
src\index.js
import React from 'react'; import * as ReactDOMClient from 'react-dom/client'; const root = ReactDOMClient.createRoot(document.getElementById('root')); root.render("Hello world");
Your index.html file code will look like below.
public\index.html
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <meta http-equiv="X-UA-Compatible" content="IE=edge"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <title>React App</title> </head> <body> <noscript> You need to enable JavaScript to run this app.</noscript> <div id="root"></div> </body> </html>
If you like what you are reading, please consider buying us a coffee ( or 2 ) as a token of appreciation.
Don't forget to share this article! Help us spread the word by clicking the share button below.
We appreciate your support and are committed to providing you valuable and informative content.
We are thankful for your never ending support.
Random Code Snippet Queries: React
- React-dom.development.js:86 Warning: validateDOMNesting(...):
- Module not found: Error: Can't resolve 'prop-types'
- Uncaught Error: useHref() may be used only in the context of a <Router> component
- How to pass dynamic URL to Link in react ?
- Get the ID from a URL in React and React Router
- Module Not Found: Can’T Resolve ‘Jquery’ In React
- How do I link to an external URL in React?
- We're unable to detect target browsers. react app