Skip to content

Instantly share code, notes, and snippets.

@foysavas
Created February 13, 2014 20:22
Show Gist options
  • Save foysavas/8983065 to your computer and use it in GitHub Desktop.
Save foysavas/8983065 to your computer and use it in GitHub Desktop.
template example for react.js
var Timer = React.createClass({
getInitialState: function() {
return {secondsElapsed: 0};
},
tick: function() {
this.setState({secondsElapsed: this.state.secondsElapsed + 1});
},
componentDidMount: function() {
this.interval = setInterval(this.tick, 1000);
},
componentWillUnmount: function() {
clearInterval(this.interval);
},
render: function() {
return __TEMPLATE__;
}
});
__TEMPLATE__
<div>Seconds Elapsed: {this.state.secondsElapsed}</div>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment