Created
April 26, 2015 22:49
-
-
Save justinobney/d41ec5537ddbc273d227 to your computer and use it in GitHub Desktop.
ReactJS learning. Clock using tock js class
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
// Clock Component | |
var timer; | |
var Clock = React.createClass({ | |
componentDidMount: function() { | |
var self = this; | |
timer = new Tock({ | |
countdown: false, | |
interval: 10, | |
callback: function() { | |
self.setState({ | |
time: timer.msToTime(timer.lap()) | |
}) | |
} | |
}); | |
}, | |
getInitialState: function() { | |
return { | |
time: '' | |
} | |
}, | |
render: function() { | |
return ( | |
<div> | |
<label>{this.state.time}</label> | |
<br /> | |
<button type="button" onClick={this.start}>Start</button> | |
<button type="button" onClick={this.pause}>Pause</button> | |
<button type="button" onClick={this.reset}>Reset</button> | |
</div>); | |
}, | |
start: function(){ | |
timer.start(timer.lap()); | |
}, | |
pause: function(){ | |
timer.pause(); | |
}, | |
reset: function(){ | |
timer.start(0); | |
} | |
}); | |
React.render(<Clock /> , document.getElementById('content')); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment