import { _ as _extends } from '../_rollupPluginBabelHelpers-736b301a.js';
import React__default from 'react';

class ErrorBoundary extends React__default.Component {
  constructor() {
    super();
    this.state = {
      hasError: false
    };
  }
  componentDidCatch(error, info) {
    this.setState({
      hasError: true
    });
    console.error(`ErrorBoundary 捕获组件内部错误！`, error, info);
  }
  render() {
    if (this.state.hasError) {
      return /*#__PURE__*/React__default.createElement("div", {
        className: "ErrorBoundary"
      });
    }
    return this.props.children;
  }
}

/**
 * 错误边界处理
 * @param {Component} WrappedComponent
 */
function errorBoundary(WrappedComponent) {
  class ErrorBoundaryWithComponent extends React__default.Component {
    render() {
      const {
        forwardRef,
        ...props
      } = this.props;
      return /*#__PURE__*/React__default.createElement(ErrorBoundary, null, /*#__PURE__*/React__default.createElement(WrappedComponent, _extends({}, props, {
        ref: forwardRef
      })));
    }
  }
  return /*#__PURE__*/React__default.forwardRef((props, ref) => /*#__PURE__*/React__default.createElement(ErrorBoundaryWithComponent, _extends({}, props, {
    forwardRef: ref
  })));
}

export { errorBoundary as default };
//# sourceMappingURL=index.js.map
