Skip to content

Instantly share code, notes, and snippets.

@mathieulesniak
Created October 2, 2016 14:50
Show Gist options
  • Save mathieulesniak/03d37188832792ce55f1cf4ebc998dbf to your computer and use it in GitHub Desktop.
Save mathieulesniak/03d37188832792ce55f1cf4ebc998dbf to your computer and use it in GitHub Desktop.
import React from 'react';
class Timer extends React.Component {
constructor(props) {
super(props);
this.state = {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>Seconds Elapsed: {this.state.secondsElapsed}</div>
);
}
}
export default Timer;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment