diff --git a/examples/package.json b/examples/package.json index ea7b016..7d7d0c9 100644 --- a/examples/package.json +++ b/examples/package.json @@ -18,7 +18,7 @@ "@types/react": "^16.8.15", "@types/react-dom": "16.8.4", "react": "^16.8.6", - "react-countdown-now": "^2.1.1", + "react-countdown-now": "^2.1.2", "react-dom": "^16.8.6", "react-scripts": "3.0.0", "typescript": "3.4.5" diff --git a/examples/yarn.lock b/examples/yarn.lock index 567595a..36c1079 100644 --- a/examples/yarn.lock +++ b/examples/yarn.lock @@ -7871,10 +7871,10 @@ react-app-polyfill@^1.0.0: regenerator-runtime "0.13.2" whatwg-fetch "3.0.0" -react-countdown-now@^2.1.1: - version "2.1.1" - resolved "https://registry.yarnpkg.com/react-countdown-now/-/react-countdown-now-2.1.1.tgz#88901eb776907338da137effbf7cdbec5b9274c6" - integrity sha512-DGSd/EGzigIsixQNzPQbk376zG49IVAyMCUkMgDEuIXlIRKQwB44Fg8uA3zrZ+aQVAuzsyb6fJWskPxIP56DYg== +react-countdown-now@^2.1.2: + version "2.1.2" + resolved "https://registry.yarnpkg.com/react-countdown-now/-/react-countdown-now-2.1.2.tgz#b93d153fbb7a8d359beb32ecbf1de29d15f026c7" + integrity sha512-BgRnsxV2vnvyJAefDBigTX+ngX6eGd2xl6DIFdZPIZkbx0mzxlMEeoEQG01JyeHDjqaXFUpIonIbx1yYyaMwzg== dependencies: lodash.isequal "^4.5.0" prop-types "^15.7.2" diff --git a/package.json b/package.json index 1423835..1c6c96b 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "react-countdown-now", - "version": "2.1.1", + "version": "2.1.2", "description": "A customizable countdown component for React.", "main": "./dist/index.js", "module": "./dist/index.es.js", diff --git a/src/Countdown.tsx b/src/Countdown.tsx index 108ad84..7758afd 100644 --- a/src/Countdown.tsx +++ b/src/Countdown.tsx @@ -117,12 +117,12 @@ export default class Countdown extends React.Component { const { onTick } = this.props; - const delta = this.calcTimeDelta(); + const timeDelta = this.calcTimeDelta(); - this.setTimeDeltaState({ ...delta }); + this.setTimeDeltaState({ ...timeDelta }); - if (onTick && delta.total > 0) { - onTick(delta); + if (onTick && timeDelta.total > 0) { + onTick(timeDelta); } }; @@ -160,9 +160,11 @@ export default class Countdown extends React.Component { + this.clearInterval(); this.setState({ offsetStart: this.calcOffsetStart() }, () => { - this.clearInterval(); - this.props.onPause && this.props.onPause(this.calcTimeDelta()); + const timeDelta = this.calcTimeDelta(); + this.setTimeDeltaState(timeDelta); + this.props.onPause && this.props.onPause(timeDelta); }); }; @@ -178,17 +180,17 @@ export default class Countdown extends React.Component this.props.onComplete && this.props.onComplete(delta); + callback = () => this.props.onComplete && this.props.onComplete(timeDelta); } if (this.mounted) { - return this.setState({ timeDelta: delta }, callback); + return this.setState({ timeDelta }, callback); } }