Skip to content

Instantly share code, notes, and snippets.

@asm-jaime
Last active August 13, 2016 08:48
Show Gist options
  • Save asm-jaime/e2e7e90ea382345f7140ec49cd278497 to your computer and use it in GitHub Desktop.
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
'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