Skip to content

Instantly share code, notes, and snippets.

@pfulop
Created February 8, 2017 20:26
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 pfulop/47284891d749e7fa5b9a25d73101d212 to your computer and use it in GitHub Desktop.
Save pfulop/47284891d749e7fa5b9a25d73101d212 to your computer and use it in GitHub Desktop.
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