Invoked once before the component is mounted. The return value will be used
* as the initial value of `this.state`.
*
* getInitialState: function() {
* return {
* isOn: false,
* fooBaz: new BazFoo()
* }
* }
*
正确读取的方式
this.getInitialState().isOn
在componentWillMount里面定义state
componentWillMount() {
this.setState({
isOn: false,
fooBaz: new BazFoo()
})
}
嗯。。。虽然没有用过createClass方式定义组建,但是我猜你不是isClicked没有定义,而是this.state没有定义。。。
试试这个
看过react源码吗?通过getInitialState定义的state,是不可以用this.state来获取的。
正确读取的方式
在componentWillMount里面定义state
render读取