Skip to content

Instantly share code, notes, and snippets.

@twhite96
Created January 5, 2019 06:12
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save twhite96/5af827cd1c411d5e89ce107b9c837fe2 to your computer and use it in GitHub Desktop.
Save twhite96/5af827cd1c411d5e89ce107b9c837fe2 to your computer and use it in GitHub Desktop.
Stopwatch Updater
//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