Start / Stop Timer
Medium · Refs
Build a timer with <p>Ticks: 0</p> and one button.
The button says "Start". Clicking it adds 1 to the ticks every 100ms and the button changes to "Stop". Clicking "Stop" pauses the timer (the ticks stay the same) and the button says "Start" again. Starting again continues from the current value.
Keep the interval id in a useRef so you can clear it, and clear it when the component unmounts.
Next: Countdown