Created
October 2, 2016 14:50
-
-
Save mathieulesniak/03d37188832792ce55f1cf4ebc998dbf to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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