mirror of
https://github.com/bitburner-official/bitburner-src.git
synced 2024-10-23 10:13:13 +02:00
29 lines
774 B
TypeScript
29 lines
774 B
TypeScript
|
import React, { ErrorInfo } from "react";
|
||
|
import { RecoveryRoot } from "./React/RecoveryRoot";
|
||
|
import { IRouter } from "./Router";
|
||
|
|
||
|
interface IProps {
|
||
|
router: IRouter;
|
||
|
softReset: () => void;
|
||
|
}
|
||
|
|
||
|
|
||
|
export class ErrorBoundary extends React.Component<IProps> {
|
||
|
state: { hasError: boolean }
|
||
|
constructor(props: IProps) {
|
||
|
super(props);
|
||
|
this.state = { hasError: false };
|
||
|
}
|
||
|
componentDidCatch(error: Error, errorInfo: ErrorInfo): void {
|
||
|
console.error(error, errorInfo);
|
||
|
}
|
||
|
render(): React.ReactNode {
|
||
|
if (this.state.hasError) {
|
||
|
return <RecoveryRoot router={this.props.router} softReset={this.props.softReset} />;
|
||
|
}
|
||
|
return this.props.children;
|
||
|
}
|
||
|
static getDerivedStateFromError(): { hasError: true} {
|
||
|
return { hasError: true };
|
||
|
}
|
||
|
}
|