@kubit-ui-web/react-components
Version:
Kubit React Components is a customizable, accessible library of React web components, designed to enhance your application's user experience
38 lines • 1.44 kB
JavaScript
;
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.ErrorBoundary = void 0;
const react_1 = __importDefault(require("react"));
const errorBoundaryContext_1 = require("./errorBoundaryContext");
class ErrorBoundary extends react_1.default.Component {
constructor(props) {
super(props);
this.state = { hasError: false, resetCondition: props.resetCondition };
}
static getDerivedStateFromError() {
return { hasError: true };
}
static getDerivedStateFromProps(props, state) {
if (props.resetCondition !== state.resetCondition) {
return { hasError: false, resetCondition: props.resetCondition };
}
return null;
}
componentDidCatch(error) {
const { getErrors } = this.context;
getErrors({ error: error.message, errorInfo: error.stack });
return { hasError: true };
}
render() {
const { customFallback } = this.context;
if (this.state.hasError || this.props.error) {
return customFallback || this.props.fallBackComponent;
}
return this.props.children;
}
}
exports.ErrorBoundary = ErrorBoundary;
ErrorBoundary.contextType = errorBoundaryContext_1.ErrorBoundaryContext;
//# sourceMappingURL=errorBoundary.js.map