Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 10 additions & 3 deletions packages/rax-countdown/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ class Index extends Component {
};

timeoutId = 0;
startTime = 0;

static propTypes = {
formatFunc: PropTypes.func,
Expand Down Expand Up @@ -67,6 +68,7 @@ class Index extends Component {
this.setState({
timeRemaining: timeRemaining
});
this.startTime = new Date().valueOf();
}

componentDidMount() {
Expand Down Expand Up @@ -112,11 +114,16 @@ class Index extends Component {
onComplete();
} else {
this.timeoutId = !countdownComplete ? setTimeout(
() => this.setState(
() => {
const now = new Date().valueOf();
const diffTime = now - this.startTime;
this.startTime = now;
this.setState(
{
timeRemaining: timeRemaining - interval
timeRemaining: timeRemaining - diffTime
},
() => isFunction(onTick) && onTick(timeRemaining)),
() => isFunction(onTick) && onTick(timeRemaining))
},
interval
) : false;
}
Expand Down