Created
February 13, 2014 20:22
-
-
Save foysavas/8983065 to your computer and use it in GitHub Desktop.
template example for react.js
This file contains hidden or 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({ | |
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 __TEMPLATE__; | |
} | |
}); | |
__TEMPLATE__ | |
<div>Seconds Elapsed: {this.state.secondsElapsed}</div> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment