Skip to content

Instantly share code, notes, and snippets.

@relwell
Created May 21, 2018 17:56
Show Gist options
  • Save relwell/aaa93607e1010b811f9480f75b585bfa to your computer and use it in GitHub Desktop.
Save relwell/aaa93607e1010b811f9480f75b585bfa to your computer and use it in GitHub Desktop.
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