I have an existing React 17 app that started life as a create-react-app output with the TypeScript option. I wanted to change package.json to include react@18.0.0 and react-dom@18.0.0 and then start the app, and that step worked fine.
Then I tried to change the index.tsx file the way that the React 18 migration instructions tell you to do it, by changing the relevant segment in index.tsx to:
ReactDOM.createRoot(
<React.StrictMode>
<App />
</React.StrictMode>,
document.getElementById('root')
);
and either npm run build or npm run start gives me compile errors, saying that createRoot is not defined. This is probably due to the fact that I have dependencies on @types/react@17.0.43 and @types/react-dom@17.0.14. There do not seem to be any updated versions of these files from DefinitelyTyped for React 18 yet.
So, I went back and created a brand new app with npx create-react-app react18 --template typescript. It now wants react@18 and react-dom@18, but still has the old @types/ dependencies. It also gives the same compile error when you switch from render() to createRoot().
As one further step, I asked myself "what happens if we leave out TypeScript?" Created yet another app with npx create-react-app react18js. It depends on react@18.0.0 and react-dom@18.0.0 as expected, but still generates ReactDOM.render() in its index.js output.
That works, but change ReactDOM.render to ReactDOM.createRoot and you get no compile errors, but you also get no visible output if you try npm run start. It doesn't seem to render the <App/> component at all.
Am I missing something? Are the instructions not quite adequate?