Skip to content

Instantly share code, notes, and snippets.

@justinobney
Created April 26, 2015 22:49
Show Gist options
  • Save justinobney/d41ec5537ddbc273d227 to your computer and use it in GitHub Desktop.
Save justinobney/d41ec5537ddbc273d227 to your computer and use it in GitHub Desktop.
ReactJS learning. Clock using tock js class
// 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