React 18显示ReactDom。Render警告,即使我切换到新标准
我已经切换到React 18,并遵循了如何更改根的渲染方法的官方指南。
这是我的根的渲染代码:
import { createRoot } from 'react-dom/client';
const root = createRoot(document.getElementById('root') as any);
root.render(<App />);
react
和 react-dom
是^18.0.0
。
应用程序正在抛弃:
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
通过简单地进行重构,下面的代码行还将起作用
从“ react-dom/client”;
import {createroot}
从“ ./components/app”;
导入应用程序
createroot(document.getElementById(“ root”))
By simply refactoring, the line of code below will also work
import { createRoot } from "react-dom/client";
import App from "./components/App";
createRoot(document.getElementById("root")).render(<App tab="home" />);
您是否安装了
React
和React-Dom
软件包的类型定义?您需要添加和
packages,然后在
tsconfig.json
文件中设置它们。请记住,包装版本需要兼容。另外,creatoroot
方法的预期参数类型是元素| document fragment
因此,您可以使用感叹号或键入断言喜欢作为元素
。index.tsx
tsconfig.json
package.json
Have you installed type definitions for
react
andreact-dom
packages? You need to add@types/react
and@types/react-dom
packages and set them in thetsconfig.json
file. Keep in mind, package versions needs to be compatible. Also the expected parameter type of thecreateRoot
method isElement | DocumentFragment
so you can either use exclamation mark or type assertion likeas Element
.index.tsx
tsconfig.json
package.json
您可以忽略它,
已经合并了一个修复程序,但UNPKG尚未提供包含修复程序的版本。
作者:0stone0
参考:
react@react@endect@instalone in startalone in startalOne in'使用cretotoot
You can ignore it, https://github.com/facebook/react/issues/24292#issuecomment-1091690844
A fix has already been merged, but UNPKG does not yet serve the version which has the fix included.
Author: 0stone0
Reference:
react@18 in "standalone" mode and get a warning using createRoot