【发布时间】:2015-07-29 19:17:30
【问题描述】:
我正在使用带有 Babel 的 ES6 类。我有一个看起来像这样的 React 组件:
import { Component } from 'react';
export default class MyReactComponent extends Component {
getInitialState() {
return {
foo: true,
bar: 'no'
};
}
render() {
return (
<div className="theFoo">
<span>{this.state.bar}</span>
</div>
);
}
}
看起来 getInitialState 没有被调用,因为我收到了这个错误:Cannot read property 'bar' of null。
【问题讨论】:
标签: javascript reactjs