Created
May 21, 2018 17:56
-
-
Save relwell/aaa93607e1010b811f9480f75b585bfa 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
DEFAULT_INTERVAL = 5000; //ms | |
class MyComponent extends React.Component { | |
state = { | |
interval: DEFAULT_INTERVAL | |
timeoutId = setTimeout(DEFAULT_INTERVAL, someApiFunction), | |
}; | |
constructor(props) { | |
super(props); | |
this.onIntervalChange = this.onIntervalChange.bind(this); | |
} | |
onIntervalChange(val) { | |
cancelTimeout(this.state.timeoutId); | |
this.setState({ | |
interval: val, | |
timeoutId = setTimeout(DEFAULT_INTERVAL, someApiFunction), | |
}); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment