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.