Created
May 14, 2015 18:54
-
-
Save pjazdzewski1990/fa6b6fd58f96593a8d01 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
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