2016-10-04 46 views
1

我得到空白使用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

組件時,應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') 
);