【发布时间】:2018-12-26 20:33:27
【问题描述】:
我已经看过之前提出的问题,并且我已经完成了建议的所有操作:
- 从组件的导入语句中删除大括号
- 导入的 React 没有大括号
- 我用大括号试过了
index.hmtl
<head>
<title>My ChatApp</title>
</head>
<body>
<div id="app"></div>
</body>
index.js
import { Meteor } from "meteor/meteor";
import React from "react";
import { render } from "react-dom";
import ChatComponent from "../../ui/App";
Meteor.startup(() => {
render(<ChatComponent />, document.getElementById("app"));
});
App.js
import { React, Component } from "react";
class ChatComponent extends Component {
constructor(props) {
super(props);
this.state = {};
}
render() {
return <h1>Try Chatting</h1>;
}
}
export default ChatComponent;
我仍然从 App.js 文件的第 9 行(即“return”行)中收到错误“Uncaught TypeError: Cannot read property 'createElement' of undefined”。如果我将 ChatComponent 更改为函数而不是类,它将起作用,但 react 在文档中说它没有区别。我还尝试将类的构造函数部分全部注释掉/删除,但没有任何效果。我有点不知所措,为什么这不起作用。为什么它不能作为一个类工作?
【问题讨论】:
标签: javascript reactjs meteor