Files
stash/ui/v2.5/src/components/ErrorBoundary.tsx
Infinite cdadb66d85 Remove or exempt all uses of 'any
* Refactored LocalForage
* Refactored SceneFilenameParser
2020-03-01 21:04:37 +01:00

48 lines
977 B
TypeScript

import React from "react";
interface IErrorBoundaryProps {
children?: React.ReactNode,
}
type ErrorInfo = {
componentStack: string,
};
interface IErrorBoundaryState {
error?: Error;
errorInfo?: ErrorInfo;
}
export class ErrorBoundary extends React.Component<IErrorBoundaryProps, IErrorBoundaryState> {
constructor(props: IErrorBoundaryProps) {
super(props);
this.state = {};
}
public componentDidCatch(error: Error, errorInfo: ErrorInfo) {
this.setState({
error,
errorInfo
});
}
public render() {
if (this.state.errorInfo) {
// Error path
return (
<div>
<h2>Something went wrong.</h2>
<details className="error-message">
{this.state.error && this.state.error.toString()}
<br />
{this.state.errorInfo.componentStack}
</details>
</div>
);
}
// Normally, just render children
return this.props.children;
}
}