Skip to content

Instantly share code, notes, and snippets.

@kmagiera
Created July 26, 2018 10:38
Show Gist options
  • Save kmagiera/7ddfa24e3c9d3b5bf79b45778a0eba32 to your computer and use it in GitHub Desktop.
Save kmagiera/7ddfa24e3c9d3b5bf79b45778a0eba32 to your computer and use it in GitHub Desktop.
componentDidMount() {
let { countdown, hours, mins, sec } = this.props;
if (countdown) {
this._interval = setInterval(() => {
sec -= 1;
if (sec < 0) {
sec = 59;
mins -= 1;
}
if (mins < 0) {
mins = 59;
hours -= 1;
}
if (hours < 0) {
clearInterval(this._interval);
} else {
this.setState({ hours, mins, sec });
}
}, 1000);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment