Skip to content

Instantly share code, notes, and snippets.

@AlecAivazis
Last active August 29, 2015 14:19
Show Gist options
  • Save AlecAivazis/0ee25aa63fb3ed8a4332 to your computer and use it in GitHub Desktop.
Save AlecAivazis/0ee25aa63fb3ed8a4332 to your computer and use it in GitHub Desktop.
ES6 React Component
'use strict';
// the base application component for syllabus
class Test extends React.Component{
constructor(){
// create this
super();
// set the initial state
this.state = {
count: 0
};
// bind the class functions to the instance of the element
this.increment = this.increment.bind(this);
}
increment() {
this.setState({
count: this.state.count + 1
});
}
render() {
return (
<div onClick={this.increment}>
count: {this.state.count}
</div>
)
}
}
React.render(<Test/>, document.body)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment