转自:https://www.cnblogs.com/maxiaocang/p/16087320.html
当使用 React 18 版本构建项目时,在运行项目时会在控制台看到如下报错信息:
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
解决方法
修改index.js文件
- 修改ReactDom的引入路径为'react-dom/client'
- 修改render函数中ReactDom.render() 方法为:
ReactDOM.createRoot(document.getElementById('root')) .render(
更多精彩内容:各种AI课程、技能课程、黑科技软件、网站小程序源码、副业小项目、PPT模板等精品素材、电商课程、推广引流课程等,尽在 天边资源网 。