问题描述

在定义class组件的时候出现:Super expression must either be null or a function, not undefined报错!
报错信息

解决问题

原来是React.component中的component首字母没有大写!!!

React.component改写成React.Component 问题解决。

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
class Message extends React.Component {
constructor(props) {
super(props);
this.state = { messageList: props.messageList };
}
render() {
return (
<div>
{this.state.messageList.length > 0 ? (
<h2>You have {this.state.messageList.length} messages</h2>
) : (
<h3>nothing</h3>
)}
</div>
);
}
}
const arr = ["sd", "sd", "ds", "ws", "sw"];
ReactDOM.render(<Message messageList={arr} />, document.getElementById("root"));