Skip to content

Instantly share code, notes, and snippets.

@alexshyba
Created February 7, 2016 21:39
Show Gist options
  • Save alexshyba/c13d6b1b1d210bf0fd6c to your computer and use it in GitHub Desktop.
Save alexshyba/c13d6b1b1d210bf0fd6c to your computer and use it in GitHub Desktop.
Counter component
var Counter = 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 (
<div>
<h1>
Counter from '{this.props.title}' page: {this.state.secondsElapsed}
</h1>
</div>
);
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment