Skip to content

Instantly share code, notes, and snippets.

@hyukkwonepic
Created November 22, 2016 17:14
Show Gist options
  • Save hyukkwonepic/6bf60ce5d76da00d924a78ce8d6ba884 to your computer and use it in GitHub Desktop.
Save hyukkwonepic/6bf60ce5d76da00d924a78ce8d6ba884 to your computer and use it in GitHub Desktop.
var React = require('react');
var Clock = React.createClass({
propTypes: {
totalSeconds: React.PropTypes.number
},
getDefaultProps: function () {
totalSeconds: 0
},
formatSeconds: function (totalSeconds) {
var seconds = totalSeconds % 60;
var minutes = Math.floor(totalSeconds / 60);
if (seconds < 10) {
seconds = '0' + seconds;
}
if (minutes < 10) {
minutes = '0' + minutes;
}
return minutes + ":" + seconds;
},
render: function () {
var {totalSeconds} = this.props;
return (
<div className="clock">
<span className="clock-text">
{this.formatSeconds(totalSeconds)}
</span>
</div>
);
}
});
module.exports = Clock;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment