use-timer
use-timer copied to clipboard
timer not accurate in mobile
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?
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.