---
title: "Comment by linxi ye on \"Countdown timer with React\" | Hashnode"
description: "Clean breakdown of managing setInterval references with refs to avoid stale closures on pause/resume. One subtle edge case we ran into when building live global"
url: "https://hashnode.com/posts/countdown-timer-with-react/62c579ef7b0f3b700c54518c/comment/6b1135a6358fbe088ae2ebe1"
---

[Discussion](https://hashnode.com/posts/countdown-timer-with-react/62c579ef7b0f3b700c54518c)

Comment [Countdown timer with React](https://hashnode.com/posts/countdown-timer-with-react/62c579ef7b0f3b700c54518c)

[linxi ye](https://hashnode.com/@drawlesson)

[1d ago](https://hashnode.com/posts/countdown-timer-with-react/62c579ef7b0f3b700c54518c/comment/6b1135a6358fbe088ae2ebe1)

Clean breakdown of managing `setInterval` references with refs to avoid stale closures on pause/resume. One subtle edge case we ran into when building live global game-event countdowns (like our unofficial fan [Fortnite Out of Time Event Countdown](https://fortnitetreasure.com/out-of-time-event-countdown/)) is browser background-tab throttling: if you decrement `seconds - 1` inside `setInterval`, switching tabs on mobile or desktop causes the displayed clock to drift behind wall-clock time within minutes.

Storing the absolute UTC target timestamp (`targetMs`) and recomputing `Math.max(0, targetMs - Date.now())` on every tick—and pairing it with `Intl.DateTimeFormat` for automatic local timezone display—completely eliminates drift even when a user leaves the tab open for hours before an event starts.
