我使用getInitialState得到空白,一定是出了问题,但我不知道在哪里。
var counter = React.createClass({
getInitialState(){
return {
count: 0
}
},
render() {
return(
<p>value of my counter is: {this.state.count}</p>
)
}
})
ReactDOM.render(
<counter />,
document.getElementById('container')
);
Jsfiddle https://jsfiddle.net/b9bu3ssz/
答案 0 :(得分:1)
组件应为Counter
,而不是counter
var Counter = React.createClass({
getInitialState(){
return {
count: 0
}
},
render() {
return <p>value of my counter is: {this.state.count}</p>
}
})
ReactDOM.render(
<Counter />,
document.getElementById('container')
);