@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
31 lines • 1.1 kB
JavaScript
import React from 'react';
import { ErrorBoundaryContext } from './errorBoundaryContext';
export class ErrorBoundary extends React.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;
}
}
ErrorBoundary.contextType = ErrorBoundaryContext;
//# sourceMappingURL=errorBoundary.js.map