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
React团队在3月29日新推出了React v18.0版本,现在npm 默认的就是18版本,由于React 18 不再支持 ReactDOM.render。控制台会抛出错误
3.解决方法:import React from "react";
import App from "./App";
import { ReactDOM } from "react";
import {createRoot} from 'react-dom/client'
const container=document.getElementById('root');
const root=createRoot(container);
root.render(<App/>);
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)