_x000D_
class Example extends React.Component {_x000D_
constructor() {_x000D_
super();_x000D_
this.state = { time: {}, seconds: 5 };_x000D_
this.timer = 0;_x000D_
this.startTimer = this.startTimer.bind(this);_x000D_
this.countDown = this.countDown.bind(this);_x000D_
}_x000D_
_x000D_
secondsToTime(secs){_x000D_
let hours = Math.floor(secs / (60 * 60));_x000D_
_x000D_
let divisor_for_minutes = secs % (60 * 60);_x000D_
let minutes = Math.floor(divisor_for_minutes / 60);_x000D_
_x000D_
let divisor_for_seconds = divisor_for_minutes % 60;_x000D_
let seconds = Math.ceil(divisor_for_seconds);_x000D_
_x000D_
let obj = {_x000D_
"h": hours,_x000D_
"m": minutes,_x000D_
"s": seconds_x000D_
};_x000D_
return obj;_x000D_
}_x000D_
_x000D_
componentDidMount() {_x000D_
let timeLeftVar = this.secondsToTime(this.state.seconds);_x000D_
this.setState({ time: timeLeftVar });_x000D_
}_x000D_
_x000D_
startTimer() {_x000D_
if (this.timer == 0 && this.state.seconds > 0) {_x000D_
this.timer = setInterval(this.countDown, 1000);_x000D_
}_x000D_
}_x000D_
_x000D_
countDown() {_x000D_
// Remove one second, set state so a re-render happens._x000D_
let seconds = this.state.seconds - 1;_x000D_
this.setState({_x000D_
time: this.secondsToTime(seconds),_x000D_
seconds: seconds,_x000D_
});_x000D_
_x000D_
// Check if we're at zero._x000D_
if (seconds == 0) { _x000D_
clearInterval(this.timer);_x000D_
}_x000D_
}_x000D_
_x000D_
render() {_x000D_
return(_x000D_
<div>_x000D_
<button onClick={this.startTimer}>Start</button>_x000D_
m: {this.state.time.m} s: {this.state.time.s}_x000D_
</div>_x000D_
);_x000D_
}_x000D_
}_x000D_
_x000D_
ReactDOM.render(<Example/>, document.getElementById('View'));
_x000D_
<script src="https://cdnjs.cloudflare.com/ajax/libs/react/15.1.0/react.min.js"></script>_x000D_
<script src="https://cdnjs.cloudflare.com/ajax/libs/react/15.1.0/react-dom.min.js"></script>_x000D_
<div id="View"></div>
_x000D_