Current Path : /storage/v11800/alliedessence/public_html/wp-content/plugins/lottiefiles/src/components/ |
Linux v11800 5.3.0-1023-aws #25~18.04.1-Ubuntu SMP Fri Jun 5 15:19:18 UTC 2020 aarch64
|
Current File : /storage/v11800/alliedessence/public_html/wp-content/plugins/lottiefiles/src/components/ErrorBoundary.tsx |
/**
* Copyright 2022 Design Barn Inc.
*/
import * as React from 'react';
import { ErrorBoundaryFallback } from './ErrorBoundaryFallback';
export interface ErrorInfo {
componentStack: string;
}
export interface ErrorBoundaryProps {
readonly children: React.ReactNode;
onError?: (error: Error, componentStack: string) => void;
}
export interface ErrorBoundaryState {
error: Error | null;
errorInfo: ErrorInfo | null;
}
export class ErrorBoundary extends React.Component<ErrorBoundaryProps, ErrorBoundaryState> {
// eslint-disable-next-line @typescript-eslint/explicit-member-accessibility
state: ErrorBoundaryState = {
error: null,
errorInfo: null,
};
// eslint-disable-next-line @typescript-eslint/explicit-member-accessibility
static getDerivedStateFromError(error: Error): ErrorBoundaryState {
return { error, errorInfo: null };
}
// eslint-disable-next-line @typescript-eslint/explicit-member-accessibility
componentDidCatch(error: Error, errorInfo: ErrorInfo): void {
const { onError } = this.props;
if (typeof onError === 'function') {
try {
onError.call(this, error, errorInfo.componentStack);
} catch (_) {
/** */
}
}
this.setState({ errorInfo });
}
// eslint-disable-next-line @typescript-eslint/explicit-member-accessibility
render(): React.ReactNode {
const { children } = this.props;
const { error, errorInfo } = this.state;
if (error !== null) {
return <ErrorBoundaryFallback error={error} stack={errorInfo?.componentStack || ''} />;
}
return children;
}
}