Created
February 8, 2017 20:26
-
-
Save pfulop/47284891d749e7fa5b9a25d73101d212 to your computer and use it in GitHub Desktop.
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
constructor() { | |
super(); | |
this.state = { | |
number: 0, | |
}; | |
this.timer = null; | |
this.addOne = this.addOne.bind(this); | |
this.stopTimer = this.stopTimer.bind(this); | |
} | |
addOne() { | |
this.setState({number: this.state.number+1}); | |
this.timer = setTimeout(this.addOne, 200); | |
} | |
stopTimer() { | |
clearTimeout(this.timer); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment