mirror of
https://github.com/Kong/insomnia
synced 2024-11-08 23:00:30 +00:00
8452e8b777
* Fixed duplication kve bug * Some changes * Add proptypes linting * Fixed proptypes even more * Filename linting
35 lines
646 B
JavaScript
35 lines
646 B
JavaScript
import {PureComponent, PropTypes} from 'react';
|
|
import autobind from 'autobind-decorator';
|
|
|
|
@autobind
|
|
class Lazy extends PureComponent {
|
|
constructor (props) {
|
|
super(props);
|
|
this.state = {show: false};
|
|
}
|
|
|
|
show () {
|
|
this.setState({show: true});
|
|
}
|
|
|
|
componentWillMount () {
|
|
if (this.props.delay < 0) {
|
|
// Show right away if negative delay passed
|
|
this.show();
|
|
} else {
|
|
setTimeout(this.show, this.props.delay || 50);
|
|
}
|
|
}
|
|
|
|
render () {
|
|
return this.state.show ? this.props.children : null;
|
|
}
|
|
}
|
|
|
|
Lazy.propTypes = {
|
|
delay: PropTypes.number,
|
|
children: PropTypes.node
|
|
};
|
|
|
|
export default Lazy;
|