31 lines
561 B
JavaScript
Raw Normal View History

import React, { Component } from 'react';
2018-01-04 14:53:30 -08:00
import PropTypes from 'prop-types';
export default class DelayedRender extends Component {
2018-01-04 14:53:30 -08:00
static propTypes = {
children: PropTypes.node.isRequired,
};
2018-01-04 14:53:30 -08:00
state = {
show: false,
};
2018-01-04 14:53:30 -08:00
componentDidMount() {
this.showTO = setTimeout(() => {
2018-01-04 14:53:30 -08:00
this.setState({
show: true,
});
}, 1000);
}
componentWillUnmount() {
clearTimeout(this.showTO);
}
2018-01-04 14:53:30 -08:00
render() {
const { show } = this.state;
const { children } = this.props;
return show ? children : <div />;
2018-01-04 14:53:30 -08:00
}
}