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
Timercomponent that is composed of aPanelcomponent and aRunscomponent. ThePanelcomponent comprises aDisplayand aControlscomponent. TheRunscomponent is composed of multipleRuncomponents, tracking multiple laps. - The
Displaycomponent 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
Controlscomponent 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
Runcomponent renders the laps that have been tracked for a certain run using aLapscomponent. EachLapscomponent is comprised of multipleLapcomponents. - 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
Timercomponent 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
Timercomponent so that multiple timers can be created and serialized. Create aTimerscomponent to manage a collection of timers, as shown in Figure 2.