Created
January 5, 2019 06:12
-
-
Save twhite96/5af827cd1c411d5e89ce107b9c837fe2 to your computer and use it in GitHub Desktop.
Stopwatch Updater
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//updater function | |
this.setState(state => { | |
if (state.running) { | |
clearInterval(this.timer); | |
} else { | |
const startTime = Date.now() - this.state.lapse; | |
this.timer = setInterval(() => { | |
this.setState({ | |
lapse: Date.now() - startTime | |
}); | |
}); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment