Separate measuring time from refreshing the display
A timer callback is a reminder to repaint, not proof that exactly 20ms passed. If the browser is busy, callbacks can arrive late. Adding 20 on each callback undercounts elapsed time. A functional state updater fixes stale reads, but it does not fix this measurement error.
Use one elapsed-time equation
Keep the timer ID, start anchor, and saved elapsed milliseconds in refs. Keep the displayed milliseconds and running flag in state because both affect the UI. While running, compute elapsed = performance.now() - startAnchor. On resume, set startAnchor = performance.now() - savedElapsed.
For example, pause at 1,235ms, wait five seconds, then resume. Move the anchor back by 1,235ms from the new current time. After another 300ms of running, elapsed is 1,535ms: the five paused seconds are excluded.
Sample the clock when Pause is pressed
The last callback may have painted 1,220ms even though Pause is pressed at 1,235ms. Save a fresh timestamp difference in the pause handler before clearing the timer. Reusing only the last painted value loses 15ms in this example, and can lose much more when callbacks are throttled.
Prevent duplicate timers and define Reset
Use timerRef.current !== null as the synchronous guard in Start. State updates are scheduled, so a running flag alone may not guard multiple calls before the next render. Pause and Reset clear the interval and set its ref to null. Reset also zeroes saved and displayed time and sets running to false. Cleanup on unmount clears the same interval.
Choose the clock deliberately
performance.now() is monotonic and unaffected by changes to the system clock, making it useful for elapsed time within the current page. A delayed callback reads a fresh difference instead of replaying missed ticks. This does not promise continuous rendering in a background tab. Device-sleep behavior differs across browsers; persistence across reloads or sleep needs a separate product decision and clock strategy.
Format without changing the stored value
Store milliseconds. Derive centiseconds with Math.floor(ms / 10) % 100, seconds with Math.floor(ms / 1000) % 60, and total minutes with Math.floor(ms / 60000). Pad each part to at least two digits; do not wrap minutes at 60 or 100. Thus 65,270ms becomes 01:05.27.
Check the behavior
Test Pause before the first callback, a long delay between callbacks, repeated Start, pause/resume with a long paused gap, Reset while running, and unmount. Keep controls as native buttons. Give the elapsed display an accessible label without announcing every hundredth through a live region.