Only update upcoming date once the current upcoming date has ran out.
parent
d7a42d03f7
commit
c32db349d9
15
src/App.jsx
15
src/App.jsx
|
@ -45,6 +45,7 @@ class App extends React.Component {
|
|||
|
||||
componentWillUnmount() {
|
||||
clearInterval(this.interval);
|
||||
this.interval = null;
|
||||
}
|
||||
|
||||
calculateUpcomingDate() {
|
||||
|
@ -56,7 +57,19 @@ class App extends React.Component {
|
|||
}
|
||||
|
||||
updateUpcomingDate() {
|
||||
this.setState({ nextUpcomingDate: this.calculateUpcomingDate() });
|
||||
const { getNow } = this.props;
|
||||
|
||||
const nextUpcomingDate = this.calculateUpcomingDate();
|
||||
|
||||
if (this.interval) {
|
||||
const interval = moment.duration(nextUpcomingDate.diff(getNow()))
|
||||
.asMilliseconds();
|
||||
|
||||
clearInterval(this.interval);
|
||||
this.interval = setInterval(this.updateUpcomingDate.bind(this), interval);
|
||||
}
|
||||
|
||||
this.setState({ nextUpcomingDate });
|
||||
}
|
||||
|
||||
render() {
|
||||
|
|
Loading…
Reference in New Issue