2018-08-05 17:57:17 +02:00

31 lines
561 B
JavaScript

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