-
-
Notifications
You must be signed in to change notification settings - Fork 26.9k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Browser console warning about React 18 and ReactDOM.render #12219
Comments
While this should be a pretty trivial fix to the template, I must admit I was a bit surprised CRA just installed a different major version of React - wouldn't it make sense to have a setting for the major version or React it assumes? |
I have been replaced in the index.js for that error as .. import React from 'react'; import './index.css'; ReactDOM.createRoot(document.querySelector("#root")).render(<React.StrictMode></React.StrictMode>); |
I may have commented in the wrong place after reading this but I had found the issue reported from the default test when running it after an initial new project setup with create-react-app. |
No, I don't think it would make sense, since it would lead to people accidentally creating projects with old React all the time. (There is generally no reason to update a global CRA so very few people who install it would do that.) The real fix is to fix the template and get a CRA patch out. |
Perhaps a warning when the expected major version doesn't match? I understand encouraging up-to-date CRA, but "CRA will break randomly, and when it does the solution is to wait" doesn't sound like a great solution either. Edit: Kudos to the React team for making recent major version upgrades pretty painless, but there's no guarantee that will always be possible, or that people don't stick with an old CRA until multiple version bumps occur, where the errors are fatal. |
Working example in TypeScript with react-router v6: import { createRoot } from 'react-dom/client';
import { BrowserRouter } from 'react-router-dom';
import { StrictMode } from 'react';
import App from './App';
import reportWebVitals from './reportWebVitals';
import './index.css';
const container = document.getElementById('root');
const root = createRoot(container as HTMLElement);
const app = (
<StrictMode>
<BrowserRouter>
<App />
</BrowserRouter>
</StrictMode>
);
root.render(app);
reportWebVitals(); |
I replaced the code in the index.js with this one, the error disappeared. Waiting for the fixes here:
|
You can make: npm install react@18 react-dom@18 import React from 'react'; const root = ReactDOM.createRoot(document.getElementById('root')); This will fix. |
this work for me
|
npm i --save-dev @types/react-dom // if client not declare at the end of the command line, use this before... |
Describe the bug
Now that React 18 is released, creating a new project (
npx create-react-app my-project
) and running that project will show the browser console warning:The project DOES run, however.
Did you try recovering your dependencies?
N/A as a new project
npm --version is:
8.1.4
Which terms did you search for in User Guide?
Didn't find anything for "React 18" or "render" or "ReactDOM"
Environment
Steps to reproduce
npx create-react-app my-project
cd my-project
npm start
Expected behavior
No browser console errors
Actual behavior
Reproducible demo
Any project, see steps to reproduce
The text was updated successfully, but these errors were encountered: