ReactJS - ReactMount:Root元素已从其原始容器中删除。新容器

时间:2014-07-16 12:33:22

标签: javascript reactjs

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

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():

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

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

1 个答案:

答案 0 :(得分:7)

删除此行

content.innerHTML = '';

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