小智 8

当我去 React 18 时,我遇到了同样的问题:

const root = ReactDOM.createRoot(
    document.getElementById('root')
);
root.render(
    <React.StrictMode>
            <App/>
    </React.StrictMode>,
    document.getElementById("root")
);
Run Code Online (Sandbox Code Playgroud)

浏览器出错了。

您可以通过删除 root.render() 中的最后一行来删除它:

document.getElementById("root")
Run Code Online (Sandbox Code Playgroud)