Skip to content

Instantly share code, notes, and snippets.

@jonathanconway
Created April 5, 2017 07:45
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 jonathanconway/60cdeccde66657f81f6d0158ac7b017d to your computer and use it in GitHub Desktop.
Save jonathanconway/60cdeccde66657f81f6d0158ac7b017d to your computer and use it in GitHub Desktop.
React wrapper for setTimeout ⏲
import React, { PureComponent, PropTypes } from 'react';
export default class Timer extends PureComponent {
static propTypes = {
interval: PropTypes.number,
onExpiry: PropTypes.func
};
constructor(props) {
super(props);
this.state = {
timer: setTimeout(props.onExpiry, props.interval)
};
}
componentWillUnmount() {
clearTimeout(this.state.timer);
}
render() {
return null;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment