Skip to content

Commit b58f7ba

Browse files
committed
ClearInterval when timer end;
1 parent d09721b commit b58f7ba

File tree

2 files changed

+6
-5
lines changed

2 files changed

+6
-5
lines changed

package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "react-component-countdown-timer",
3-
"version": "0.1.7",
3+
"version": "0.1.8",
44
"description": "Count down timer component for react",
55
"main": "lib/index.js",
66
"scripts": {

src/lib/index.jsx

+5-4
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ export default class CountdownTimer extends Component {
2323
this.setState({ count: newCount >= 0 ? newCount : 0 }, () => {
2424
if (this.state.count === 0) {
2525
this.props.onEnd();
26+
clearInterval(this.timer);
2627
}
2728
});
2829
}, 1000);
@@ -56,10 +57,10 @@ export default class CountdownTimer extends Component {
5657
let minutes = Math.floor(time / 60) % 60;
5758
let hours = Math.floor(time / 3600) % 24;
5859
let day = Math.floor(time / 86400);
59-
day = day.toString().length === 1 ? `0${day}` : day;
60-
minutes = minutes.toString().length === 1 ? `0${minutes}` : minutes;
61-
seconds = seconds.toString().length === 1 ? `0${seconds}` : seconds;
62-
hours = hours.toString().length === 1 ? `0${hours}` : hours;
60+
day = day < 10 ? `0${day}` : day;
61+
minutes = minutes < 10 ? `0${minutes}` : minutes;
62+
seconds = seconds < 10 ? `0${seconds}` : seconds;
63+
hours = hours < 10 ? `0${hours}` : hours;
6364
if (showTitle) {
6465
const borderClass = border ? 'border' : '';
6566
const responsiveClass = responsive ? 'responsive' : '';

0 commit comments

Comments
 (0)