可能的拼写错误,我看不到? ReactDOM未定义

时间:2016-06-16 16:33:52

标签: javascript facebook reactjs

请考虑以下示例:

import React    from 'react';
import ReactDOM from 'react-dom/dist/react-dom';

class Dashboard extends React.Component {
  constructor(props) {
    super(props);

    this.state = {
      current_tab: 'home'
    }
  }

  renderActiveTab() {
    switch (this.state.current_tab) {
      case 'home':
        return (<div>Hello World</div>);
      default:
        return (<div>Hello World</div>);
    }
  }

  render() {
    return (
      <div>
        {this.renderActiveTab()}
      </div>
    )
  }
}

var dashboardElement = document.getElementById("dashboard");
console.log(dashboardElement, ReactDOM, React);

if (dashboardElement !== null) {
    ReactDOM.render(
        <Dashboard source={"//" + location.hostname + "/api/v1/blog/posts"} />,
        dashboardElement
    );
}

module.exports = Dashboard;

与...相关:

enter image description here

谁想填补我? ReactDOM似乎未定义?

我正在使用:

"react": "15.1.0",
"react-dom": "15.1.0",

这是如何定义的?

1 个答案:

答案 0 :(得分:1)

更改

import ReactDOM from 'react-dom/dist/react-dom';进入

import ReactDOM from 'react-dom';

react-dom / dist / react-dom.js文件可直接包含在脚本标记中。请参阅Development vs. Production Builds反应文档。