ReactJS - ReactMount:Root元素已从其原始容器中删除。新容器 [英] ReactJS - ReactMount: Root element has been removed from its original container. New container

查看:257
本文介绍了ReactJS - ReactMount:Root元素已从其原始容器中删除。新容器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这个错误意味着什么?如何解决这个问题?

What this error mean? How to fix that?

ReactMount: Root element has been removed from its original container. New container

在此之后我得到这个:

Uncaught object react.js:15915
invariant react.js:15915
ReactMount.findComponentRoot react.js:10584
ReactMount.findReactNodeByID react.js:10480
getNode react.js:10089
(anonymous function) react.js:7307
(anonymous function) react.js:11403
processQueue react.js:10856
ReactMultiChild.Mixin.updateChildren react.js:10970
ReactDOMComponent.Mixin._updateDOMChildren react.js:7007
(anonymous function) react.js:6860
(anonymous function) react.js:11403
ReactComponent.Mixin._performUpdateIfNecessary react.js:4409
ReactComponent.Mixin.receiveComponent react.js:4380
ReactDOMComponent.Mixin.receiveComponent react.js:6833
(anonymous function) react.js:5963
(anonymous function) react.js:11403
ReactCompositeComponentMixin._performComponentUpdate react.js:5899
ReactCompositeComponentMixin._performUpdateIfNecessary react.js:5842
Mixin.perform react.js:14266
ReactComponent.Mixin.performUpdateIfNecessary react.js:4390
ReactCompositeComponentMixin.performUpdateIfNecessary react.js:5792
enqueueUpdate react.js:12731
ReactCompositeComponentMixin.replaceState react.js:5676
ReactCompositeComponentMixin.setState react.js:5655
(anonymous function) posts.js:273
j jquery-1.11.1.min.js:2
k.fireWith jquery-1.11.1.min.js:2
x jquery-1.11.1.min.js:4
b

当我遇到这些问题时,我正在尝试使用新的项目列表更新我的视图。要更新我当前的视图,我调用updatePosts():

When I get those problems I'm trying to update my view with a new list of items. To update my current view I call updatePosts():

var updatePosts = function () {
    var content = document.querySelector('.content');
    content.innerHTML = '';
    $refresh.addClass('fa-spin');
    return React.renderComponent(
        <Posts />,
        content
    );
};

可以这个innerHTML =''问题?我将再次渲染我的帖子组件。

Can be this innerHTML = '' the problem? I'll render my Posts component entire again.

推荐答案

删除此行

content.innerHTML = '';

React将查看旧的虚拟dom,以及返回的内容<帖子/> (与帖子()相同)。它会比较它们,并对DOM进行更新。

React will look at the old virtual dom, and what's returned by <Posts /> (which is the same as Posts()). It'll compare them, and make the updates required to the DOM.

这篇关于ReactJS - ReactMount:Root元素已从其原始容器中删除。新容器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆