Lap Timer
Design and develop a lap timer that can track multiple runs and laps. An interactive demonstration is shown in Figure 1.
00:00:00.00
- Create a
Timer
component that is composed of aPanel
component and aRuns
component. ThePanel
component comprises aDisplay
and aControls
component. TheRuns
component is composed of multipleRun
components, tracking multiple laps. - The
Display
component renders the elapsed time. It receives a single prop,time
, that contains the time elapsed in milliseconds, and renders the hours, minutes, seconds, and centiseconds. - The
Controls
component renders buttons to control these actions: Start/Resume, Pause, Lap, and Stop/Reset. Each of these actions will have an associated callback to handle its click event. - The
Run
component renders the laps that have been tracked for a certain run using aLaps
component. EachLaps
component is comprised of multipleLap
components. - Create the required state variables using the
useState()
hook. How many are needed? - Create a reference using the
useRef()
hook to be able to clear a set interval. When should the reference hook be used instead of the state hook? Defer the value of the displayed time using theuseDeferredValue()
hook.- Serialize the
Timer
component and save its state in local storage so it can be reloaded between sessions. How can an effect be used to automate the serialization using theuseEffect()
hook? - Update your
Timer
component so that multiple timers can be created and serialized. Create aTimers
component to manage a collection of timers, as shown in Figure 2.