react警告之react-dom.development.js:86 Warning: ReactDOM.render is no longer supported in React 18.
react-dom.development.js:86 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. Lear
·
由于React团队在2022年3月29日推出了react 18,所以ReactDOM.render()方法不再支持,控制台会报出警告
建议你使用createRoot,注释掉的语句为之前的方法
// 引入React核心库
import React from "react";
// import ReactDOM from "react-dom";
// 引入App组件
import App from './App'
// ReactDOM.render(<App/>,document.getElementById('root'))
使用createRoot
import { createRoot } from 'react-dom/client';
const container = document.getElementById('root');
const root = createRoot(container);
root.render(<App/>);
更多推荐
已为社区贡献7条内容
所有评论(0)