react-code-view
Version:
Code view for React
29 lines • 1.13 kB
JavaScript
import _inheritsLoose from "@babel/runtime/helpers/esm/inheritsLoose";
import React from 'react';
import { jsx as _jsx } from "react/jsx-runtime";
var ErrorBoundary = /*#__PURE__*/function (_React$Component) {
function ErrorBoundary() {
return _React$Component.apply(this, arguments) || this;
}
_inheritsLoose(ErrorBoundary, _React$Component);
var _proto = ErrorBoundary.prototype;
_proto.componentDidCatch = function componentDidCatch(error, info) {
var _this$props$onError, _this$props;
(_this$props$onError = (_this$props = this.props).onError) === null || _this$props$onError === void 0 ? void 0 : _this$props$onError.call(_this$props, error, info);
};
_proto.render = function render() {
var _this$props2 = this.props,
hasError = _this$props2.hasError,
errorMessage = _this$props2.errorMessage,
children = _this$props2.children;
if (hasError) {
return /*#__PURE__*/_jsx("pre", {
className: "react-code-view-error",
children: errorMessage
});
}
return children;
};
return ErrorBoundary;
}(React.Component);
export default ErrorBoundary;