我可以打电话给“ createroot”或&quot'reactdom.render&quot&quot&quot在组件中?
我想找到一个由外部库制作的圆顶元素(例如:react-calendar ..),并希望将我的组件附加为元素的孩子。因此,我用React.Createelement制作了React Node,并手动更新了React Dome,但我收到了以下消息。
react_devtools_backend.js:3973警告:ReactDom.render不再支持React 18中的REDERNENDER。改用Croteroot。直到您切换到 新的API,您的应用将表现得好像正在运行的React 17
因此我使用了“ reactdom.createoroot()”,而不是“ reactdom.render”,但还有另一个错误。
您在以前传递给reationdom.render()的容器上调用reactdom.createOrot()。这不支持。
当我插入时,组件已添加到DOM元素,但是我有这样的错误...我应该找到另一种方法吗?
这是我的代码
parentElement.current = document.getElementsByClassName("test-parent-className")[0] as HTMLDivElement;
if (myElement.current) {
const parentRoot = ReactDOM.createRoot(parentElement.current as HTMLDivElement);
parentRoot.render(React.createElement("div", {className: "test-child"},
<div>test child component</div>))
}
...
I want to find a dome element made by an external library (ex: react-calendar..) and want to attach my component as child of the element. So, I made React node with React.createElement and updated the the react dome manually, but I got the following message.
react_devtools_backend.js:3973 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
So I used "ReactDOM.createRoot()" instead of "ReactDOM.render",but got another error.
You are calling ReactDOM.createRoot() on a container that was previously passed to ReactDOM.render(). This is not supported.
The component was added to the dom element as I inteded, but I got an error like that... should I find another method?
this is my code
parentElement.current = document.getElementsByClassName("test-parent-className")[0] as HTMLDivElement;
if (myElement.current) {
const parentRoot = ReactDOM.createRoot(parentElement.current as HTMLDivElement);
parentRoot.render(React.createElement("div", {className: "test-child"},
<div>test child component</div>))
}
...
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
认为您正在使用错误。正如错误所说,您不能像所做的那样在.render()函数中使用croteroot。
在下面尝试这样的事情:
我无法真正测试任何内容,而无需看到您的完整代码,所以我只是从我的肠子上掉下来。如果您需要进一步的帮助,请参见下面的文档。
https:///reactjs.s.orgg/blog/20222/ 03/08/react-18-upgrade-guide.html
Think you're using it wrong. As the error says, you can't be using createRoot in the .render() function as you're doing.
Try something like this below:
I can't really test anything without seeing your full code, so im just going off my gut. See docs below if you need further assistance.
https://reactjs.org/blog/2022/03/08/react-18-upgrade-guide.html