insomnia/app/ui/components/base/lazy.js
2017-08-09 18:56:27 -07:00

36 lines
671 B
JavaScript

import {PureComponent} from 'react';
import PropTypes from 'prop-types';
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;