use-timer icon indicating copy to clipboard operation
use-timer copied to clipboard

timer not accurate in mobile

Open veeramarni opened this issue 3 years ago • 1 comments

It seems if I lock my phone and get back to the browser, it slows down and after 5 minutes the timer has just counted 20 seconds. How can the timer can be current after the browser becomes active after it being minimized or phone screen locked?

veeramarni avatar Mar 05 '21 20:03 veeramarni

I ran into this problem also and it boils down to the setInterval not being the best way to implement a timer.

I think most of the issues could be fixed by you if you were to fork this repo and use the Date() to determine the time.

Here is an implementation I did for another project that should help:

https://github.com/markmccoid/healingbreath/blob/main/src/utils/timerAdjustingInterval.ts

I'm using a state machine in my project to implement the timer, but in the end that above function is what is being used to calculate the time.

markmccoid avatar Jul 19 '22 17:07 markmccoid