最新用到react的state
在初始化时却报错
null is not a object (evaluating ‘this.state.value’)】
getInitialState () {
return {num: 0};
}
无论怎么修改 ,还是频繁报错
最后发现 因为我用的是es6语法 不是使用createClass 创建组件的 而是使用 extends
用到es6的时候初始化state应该在constructor ()内,而不是用getInitialState()
class Search extends Component {
constructor () {
super();
this.state = {
....
}
}
...
}
报错解决