"use strict";

exports.__esModule = true;
exports.safeCancelAnimationFrame = exports.default = void 0;
var _react = _interopRequireDefault(require("react"));
var _propTypes = _interopRequireDefault(require("prop-types"));
function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
const safeCancelAnimationFrame = requestId => requestId && cancelAnimationFrame(requestId);
exports.safeCancelAnimationFrame = safeCancelAnimationFrame;
class Swapper extends _react.default.Component {
  constructor(props) {
    super(props);
    this.state = {
      init: true
    };
  }
  componentDidMount() {
    if (typeof requestAnimationFrame !== 'undefined') {
      this.requestID = requestAnimationFrame(() => this.setState({
        init: false
      }));
    }
  }
  componentWillUnmount() {
    if (this.requestID !== undefined) {
      safeCancelAnimationFrame(this.requestID);
    }
  }
  render() {
    const {
      init
    } = this.state;
    const {
      children,
      ...props
    } = this.props;
    const child = _react.default.Children.only(children);
    return init ? /*#__PURE__*/_react.default.cloneElement(child, props) : child;
  }
}
Swapper.propTypes = process.env.NODE_ENV !== "production" ? {
  children: _propTypes.default.node
} : {};
var _default = exports.default = Swapper;
//# sourceMappingURL=index.js.map