Skip to content

Commit f9f5add

Browse files
authored
Merge pull request #3 from rahi-nz/master
add callBack in setState
2 parents 4d1fb00 + 858d4da commit f9f5add

File tree

1 file changed

+5
-4
lines changed

1 file changed

+5
-4
lines changed

src/lib/index.jsx

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -62,10 +62,11 @@ export default class CountdownTimer extends Component {
6262
handleStart() {
6363
this.timer = setInterval(() => {
6464
const newCount = this.state.count - 1;
65-
if (newCount === 0) {
66-
this.props.onEnd();
67-
}
68-
this.setState({ count: newCount >= 0 ? newCount : 0 });
65+
this.setState({ count: newCount >= 0 ? newCount : 0 }, () => {
66+
if (this.state.count === 0) {
67+
this.props.onEnd();
68+
}
69+
});
6970
}, 1000);
7071
}
7172

0 commit comments

Comments
 (0)