47 lines
1.6 KiB
JavaScript
47 lines
1.6 KiB
JavaScript
|
"use strict";
|
||
|
Object.defineProperty(exports, "__esModule", { value: true });
|
||
|
exports.DelayedRender = void 0;
|
||
|
var tslib_1 = require("tslib");
|
||
|
var React = require("react");
|
||
|
var getWindow_1 = require("./dom/getWindow");
|
||
|
/**
|
||
|
* Utility component for delaying the render of a child component after a given delay. This component
|
||
|
* requires a single child component; don't pass in many components. Wrap multiple components in a DIV
|
||
|
* if necessary.
|
||
|
*
|
||
|
* @public
|
||
|
* {@docCategory DelayedRender}
|
||
|
*/
|
||
|
var DelayedRender = exports.DelayedRender = /** @class */ (function (_super) {
|
||
|
tslib_1.__extends(DelayedRender, _super);
|
||
|
function DelayedRender(props) {
|
||
|
var _this = _super.call(this, props) || this;
|
||
|
_this.state = {
|
||
|
isRendered: (0, getWindow_1.getWindow)() === undefined,
|
||
|
};
|
||
|
return _this;
|
||
|
}
|
||
|
DelayedRender.prototype.componentDidMount = function () {
|
||
|
var _this = this;
|
||
|
var delay = this.props.delay;
|
||
|
// eslint-disable-next-line no-restricted-globals
|
||
|
this._timeoutId = window.setTimeout(function () {
|
||
|
_this.setState({
|
||
|
isRendered: true,
|
||
|
});
|
||
|
}, delay);
|
||
|
};
|
||
|
DelayedRender.prototype.componentWillUnmount = function () {
|
||
|
if (this._timeoutId) {
|
||
|
clearTimeout(this._timeoutId);
|
||
|
}
|
||
|
};
|
||
|
DelayedRender.prototype.render = function () {
|
||
|
return this.state.isRendered ? React.Children.only(this.props.children) : null;
|
||
|
};
|
||
|
DelayedRender.defaultProps = {
|
||
|
delay: 0,
|
||
|
};
|
||
|
return DelayedRender;
|
||
|
}(React.Component));
|
||
|
//# sourceMappingURL=DelayedRender.js.map
|