---
title: "Discussion on \"Countdown timer with React\" | Hashnode"
description: "Discussion on \"Countdown timer with React\". Navigating the quirks of React's state and component model to build a countdown timer you can start, pause, resume, stop and reset. Idea is to start an interval and keep track of it's reference in a ref. On pausing said timer, we can clear the interv..."
url: "https://hashnode.com/posts/countdown-timer-with-react/62c579ef7b0f3b700c54518c"
---

[Feed](https://hashnode.com/feed) /

Discussion

# [Countdown timer with React](https://rohanbagchi.hashnode.dev/countdown-timer-with-react?utm_source=hashnode&utm_medium=feed)

Navigating the quirks of React's state and component model to build a countdown timer you can start, pause, resume, stop and reset. Idea is to start an interval and keep track of it's reference in a ref. On pausing said timer, we can clear the interv...

Mar 5, 2022 · 3 min read · rohanbagchi.hashnode.dev  
Updated May 25, 2023  
Read the article

-   [#reactjs](https://hashnode.com/tag/reactjs)
-   [#countdown-timer](https://hashnode.com/tag/countdown-timer)
-   [#javascript](https://hashnode.com/tag/javascript)

## Written by

[Rohan Bagchi](https://hashnode.com/@rohanBagchi)

@rohanBagchi · Bangalore, India

  
[View profile](https://hashnode.com/@rohanBagchi)

Engineer at Atlassian

## Responses 1

Markdown supported · ⌘↵ to post

[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.
