Last active
August 13, 2016 08:48
-
-
Save asm-jaime/e2e7e90ea382345f7140ec49cd278497 to your computer and use it in GitHub Desktop.
easy es6/state/props react counter, full project on github.com/asm-jaime/easy-react
This file contains hidden or 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
'use strict'; | |
const React = require('react'); | |
const ReactDOM = require('react-dom'); | |
export class Counter extends React.Component { | |
constructor(props) { | |
super(props); | |
this.state = {count: props.initialCount}; | |
this.tick = this.tick.bind(this); | |
} | |
tick() { | |
this.setState({count: this.state.count + 1}); | |
} | |
render() { | |
return ( | |
<div onClick={this.tick}> | |
Clicks: {this.state.count} | |
</div> | |
); | |
} | |
} | |
Counter.propTypes = { initialCount: React.PropTypes.number }; | |
Counter.defaultProps = { initialCount: 8 }; | |
ReactDOM.render(<Counter /> , document.querySelector('body')); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment