Skip to content

Instantly share code, notes, and snippets.

@pjazdzewski1990
Created May 14, 2015 18:54
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
Save pjazdzewski1990/fa6b6fd58f96593a8d01 to your computer and use it in GitHub Desktop.
var Timer = React.createClass({
getDefaultProps: function() {
return {label: "Timer"}
},
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 (
{this.props.label}
Seconds Elapsed: {this.state.secondsElapsed}
);
}
});
React.render(<Timer label={"Sample timer"}/>, mountNode);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment