Created
July 24, 2017 15:22
-
-
Save anonymous/d02a9c8851d73c990954403e28cc35b7 to your computer and use it in GitHub Desktop.
React Counter
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<div id="root"> | |
<!-- This element's contents will be replaced with your component. --> | |
</div> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Counter extends React.Component { | |
constructor(props) { | |
super(props); | |
this.state = { count: 0 }; | |
this.increment = this.increment.bind(this); | |
this.decrement = this.decrement.bind(this); | |
} | |
render() { | |
return ( | |
<div> | |
<h3> Counter </h3> | |
<div onClick={this.increment}> + </div> | |
<div> {this.state.count} </div> | |
<div onClick={this.decrement}> - </div> | |
</div> | |
) | |
} | |
decrement() { | |
this.setState({count: --this.state.count}); | |
} | |
increment() { | |
this.setState({count: ++this.state.count}); | |
} | |
} | |
ReactDOM.render( | |
<Counter />, | |
document.getElementById('root') | |
); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<script src="https://cdnjs.cloudflare.com/ajax/libs/react/15.3.1/react.min.js"></script> | |
<script src="https://cdnjs.cloudflare.com/ajax/libs/react/15.3.1/react-dom.min.js"></script> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment