React.unmountComponentAtNode | 15.4.1 |对象不支持属性或方法' unmountComponentAtNode'

时间:2017-12-14 17:26:24

标签: javascript reactjs react-native redux react-redux

我使用以下声明导入

let data = [
    48
    ,47.71306060387108
    ,47.250273223993105
    ,46.59686907269243
    ,45.71876416434013
    ,44.53304242029258
    ,42.745236969423615
    ,{re: 40.38334500994142, im:1.919295696316476, __ember1513267958317: "ember368"}
    ,{ re:39.55961661806138, im:3.8933604519196416, __ember1513267958317: "ember369"}
]

let result = data.map((x) => x && x.re ? x.re : x);


let resultTwo = data.map(function(elem) {
    // First, we need to check that the array element is not null / undefined
    // We then need to check that it has a property called re that is also not null / undefined
    if (elem != null && elem.re != null) {
        // Just return the property we're interested in
        return elem.re;
    } else {
        // Return the element as is
        return elem;
    }
});

console.log(result);
console.log(resultTwo);

我希望使用import React, { Component } from 'react'; ,但不断收到错误

  

对象不支持属性或方法' unmountComponentAtNode'

     

React.unmountComponentAtNode(的document.getElementById('根'));

我使用旧版本的React库(15.4.1)。

那么我该如何调用unmountComponentAtNode以便我不会收到错误:

  

unmountComponentAtNode不会被' react'?

导出

我应该导入什么以便我不会收到错误?

1 个答案:

答案 0 :(得分:1)

v15.4中的big change是React和ReactDOM的分离。 unmountComponentAtNode()成为ReactDOM的方法。使用:

ReactDOM.unmountComponentAtNode(document.getElementById('root'));