# 745 MINReact Chrono: Start/Pause & Stop
# 7
45 MIN
Overview
Build a simple chronometer in React with two buttons: Start/Pause (toggle) and Stop (reset).
Solution preview
Here's the result you'll build by completing this challenge.
Requirements
- Display the timer starting at
00:00.0. - Toggle the timer with a Start/Pause button:
- Start counting when pressed.
- Pause counting when pressed again.
- Reset the timer to
00:00.0with a Stop button. - Update the timer display in tenths of a second while running.
- Ensure that multiple presses of Start/Pause behave correctly (do not create multiple intervals).
- Make the buttons accessible with proper
aria-labels (Play, Pause, Stop)
Notes
- Use
setIntervalandclearIntervalto control the timer. - Consider storing the interval ID in state or a ref to manage starting and stopping correctly.
- Starting and stopping the interval inside the event handlers is fine here because the timer's running state is driven by user actions, not by a value that changes on every render. There is no reactive value to keep in sync, so no effect is needed to create the interval.
- In this challenge the chrono is always mounted, but in a real app it could unmount at any time (client-side navigation, hot reload). Clear the interval on unmount (return a cleanup function from
useEffect) so it does not keep running in the background. - Formatting the timer into minutes, seconds, and tenths can be done with helper functions.
- This challenge intentionally counts ticks for simplicity. In production, timers usually derive elapsed time from timestamps (
Date.now()) instead of counting executions, to avoid drift. - Tests check the buttons’ aria-labels, so make sure to add them.
Tests
- renders the timer at 00:00.0 initially
- starts counting when Play is pressed
- pauses when Pause is pressed
- can resume after pausing
- resets to 00:00.0 when Stop is pressed