28 lines
738 B
TypeScript
28 lines
738 B
TypeScript
import { Component, type ErrorInfo, type ReactNode } from "react";
|
|
|
|
export class ErrorBoundary extends Component<
|
|
{ children: ReactNode },
|
|
{ error?: Error }
|
|
> {
|
|
state: { error?: Error } = {};
|
|
static getDerivedStateFromError(error: Error) {
|
|
return { error };
|
|
}
|
|
componentDidCatch(error: Error, info: ErrorInfo) {
|
|
console.error("Application failure", error, info);
|
|
}
|
|
render() {
|
|
if (this.state.error)
|
|
return (
|
|
<main className="fatal">
|
|
<h1>Fixture Tools could not continue</h1>
|
|
<p>{this.state.error.message}</p>
|
|
<button type="button" onClick={() => location.reload()}>
|
|
Reload
|
|
</button>
|
|
</main>
|
|
);
|
|
return this.props.children;
|
|
}
|
|
}
|