0

I have a Countdown timer in my react native App. Please take a look into the below javascript code.

let deadline = new Date(Date.parse(new Date()) + 2 * 60 * 60 * 1000);
let Counter = setInterval(function () {
   let decreaseValue = new Date().getTime();
   let distance = deadline - decreaseValue;
   let hours = Math.floor((distance % (1000 * 60 * 60 * 24)) / (1000 * 60 * 60));
   let minutes = Math.floor((distance % (1000 * 60 * 60)) / (1000 * 60));
   let seconds = Math.floor((distance % (1000 * 60)) / 1000);

   if (distance < 0) {
       clearInterval(Counter);
   }
}, 1000);

This is a working code. Timer will be started from 2 hours: 59 minutes:59 seconds and ends at 0.

Now the problem is I want to show hours, minutes, seconds in my UI. I have tried render it by useMemo, external Component, state variable. Still it is not working.

Please Share your ideas. Thanks in Advance.

M.Kalidass
  • 338
  • 1
  • 4
  • 18

1 Answers1

1

I think this question relates to this post Countdown timer in React You can find how to implement a countdown timer in this post

Kevin Liao
  • 313
  • 2
  • 7