ReactDOM.render 在react 18中已经被弃用,会警告以兼容模式运行,文档:官方文档Deprecations:react-dom: ReactDOM.render has been deprecated. Using it will warn and run your app in React 17 mode.react-dom: ReactDOM.hydrate has been deprecated. Using it will warn and run your app in React 17 mode.react-dom: ReactDOM.unmountComponentAtNode has been deprecated.react-dom: ReactDOM.renderSubtreeIntoContainer has been deprecated.react-dom/server: ReactDOMServer.renderToNodeStream has been deprecated.你要不就恢复到之前的react 17版本,要不就用以下示例代码替换:Example:import { StrictMode } from "react"; import { createRoot } from "react-dom/client"; import App from "./App"; const rootElement = document.getElementById("root"); const root = createRoot(rootElement); // 👈 使用 createRoot() // 👇 使用 root.render() root.render( <StrictMode> <App /> </StrictMode> );
ReactDOM.render 在react 18中已经被弃用,会警告以兼容模式运行,文档:官方文档
Deprecations:
你要不就恢复到之前的react 17版本,要不就用以下示例代码替换:
Example: