Skip to content
Advertisement

how to save a variable with the current data saved in an interval updating state

I am builidng a typicall stopwatch/clock app in here.

The issue: When clicking Pause Button then Split Button (which prints the elapsed time) and then start back, both the stopwatch and the printed time restart. That is because I am saving the Crono time in the handleClickSplit function. Any ideas on the best way to save that current paused time to prevent the bug?

This is the image

enter image description here

This is my code:

JavaScript

Advertisement

Answer

You’re saving in your printTime array a reference to the very same cronoTime object. Just save a new object, so that changes on cronoTime do not propagate to the object in printTime:

JavaScript
User contributions licensed under: CC BY-SA
6 People found this is helpful
Advertisement