1.2.1 JSX

判斷一個元素是HTML還是React組件的原則就是看第一個字母是否大寫,

import React,{Component} from 'react';
class ClickCounter extends Component{
  constructor(props){
    super(props);
    this.onClickButton = this.onClickButton.bind(this);
    this.state = {count:0};
  }
onClickButton(){
  this.setState({count:this.state.count+1});
}

render(){
  const counterStyle ={
    margin:'26px'
  }
  return(
    <div style={counterStyle}>
      <button onClick ={this.onClickButton}> Click Me</button>

    <div>
      Click Count:<span id="clickCount">{this.state.count}</span>
    </div>
    </div>
  );
}
}

export default  ClickCounter;
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章