diff --git a/completed/CountdownTimer/app/components/Countdown.jsx b/completed/CountdownTimer/app/components/Countdown.jsx index b4e969b..f11e0a8 100644 --- a/completed/CountdownTimer/app/components/Countdown.jsx +++ b/completed/CountdownTimer/app/components/Countdown.jsx @@ -23,9 +23,11 @@ class Countdown extends React.Component { tick() { this.timer = setInterval(() => { - var newCount = this.state.count - 1; - this.setState({ - count: newCount >= 0 ? newCount : 0 + this.setState(oldState => { + const newCount = this.state.count - 1; + return { + count: newCount >= 0 ? newCount : 0 + }; }); }, 1000); } diff --git a/completed_with_auth0/CountdownTimer/app/components/Countdown.jsx b/completed_with_auth0/CountdownTimer/app/components/Countdown.jsx index b4e969b..f11e0a8 100644 --- a/completed_with_auth0/CountdownTimer/app/components/Countdown.jsx +++ b/completed_with_auth0/CountdownTimer/app/components/Countdown.jsx @@ -23,9 +23,11 @@ class Countdown extends React.Component { tick() { this.timer = setInterval(() => { - var newCount = this.state.count - 1; - this.setState({ - count: newCount >= 0 ? newCount : 0 + this.setState(oldState => { + const newCount = this.state.count - 1; + return { + count: newCount >= 0 ? newCount : 0 + }; }); }, 1000); } diff --git a/starter/CountdownTimer/app/components/Countdown.jsx b/starter/CountdownTimer/app/components/Countdown.jsx index b4e969b..f11e0a8 100644 --- a/starter/CountdownTimer/app/components/Countdown.jsx +++ b/starter/CountdownTimer/app/components/Countdown.jsx @@ -23,9 +23,11 @@ class Countdown extends React.Component { tick() { this.timer = setInterval(() => { - var newCount = this.state.count - 1; - this.setState({ - count: newCount >= 0 ? newCount : 0 + this.setState(oldState => { + const newCount = this.state.count - 1; + return { + count: newCount >= 0 ? newCount : 0 + }; }); }, 1000); }