title: Countdown timer in React
body: <p>I have seen lots of countdown timers in JavaScript and wanted to get one working in React.</p>
  
  <p>I have borrowed this function I found online:</p>
  
  <pre><code>secondsToTime(secs){
      let hours = Math.floor(secs / (60 * 60));
  
      let divisor_for_minutes = secs % (60 * 60);
      let minutes = Math.floor(divisor_for_minutes / 60);
  
      let divisor_for_seconds = divisor_for_minutes % 60;
      let seconds = Math.ceil(divisor_for_seconds);
  
      let obj = {
          "h": hours,
          "m": minutes,
          "s": seconds
      };
      return obj;
    };
  </code></pre>
  
  <p>And then I have written this code myself</p>
  
  <pre><code>  initiateTimer = () =&gt; {
      let timeLeftVar = this.secondsToTime(60);
      this.setState({ timeLeft: timeLeftVar })
    };
  
    startTimer = () =&gt; {
      let interval = setInterval(this.timer, 1000);
      this.setState({ interval: interval });
    };
  
    timer = () =&gt; {
      if (this.state.timeLeft &gt;0){
        this.setState({ timeLeft: this.state.timeLeft -1 });
      }
      else {
        clearInterval(this.state.interval);
        //this.postToSlack();
      }
    };
  </code></pre>
  
  <p>Currently onclick it will set the time on screen to: <code>Time Remaining: 1 m : 0 s</code>
  But it does not reduce it to <code>Time Remaining: 0 m : 59 s</code> and then <code>Time Remaining: 0 m : 58 s</code> etc etc</p>
  
  <p>I think I need to call the function again with a different parameter. how can I go about doing this ?</p>
  
  <p><em>Edit: I forgot to say, I would like the functionality so that I can use seconds to minutes &amp; seconds</em></p>