aboutsummaryrefslogtreecommitdiff
path: root/src/ErrorBoundary.tsx
diff options
context:
space:
mode:
Diffstat (limited to 'src/ErrorBoundary.tsx')
-rw-r--r--src/ErrorBoundary.tsx20
1 files changed, 16 insertions, 4 deletions
diff --git a/src/ErrorBoundary.tsx b/src/ErrorBoundary.tsx
index d3f5a60..2372f9b 100644
--- a/src/ErrorBoundary.tsx
+++ b/src/ErrorBoundary.tsx
@@ -6,16 +6,23 @@ interface ErrorBoundaryProps {
interface ErrorBoundaryState {
hasError: boolean;
+ error: Error | null;
}
class ErrorBoundary extends Component<ErrorBoundaryProps, ErrorBoundaryState> {
constructor(props: ErrorBoundaryProps) {
super(props);
- this.state = { hasError: false };
+ this.state = {
+ hasError: false,
+ error: null
+ };
}
- static getDerivedStateFromError(_: Error): ErrorBoundaryState {
- return { hasError: true };
+ static getDerivedStateFromError(error: Error): ErrorBoundaryState {
+ return {
+ hasError: true,
+ error
+ };
}
componentDidCatch(error: Error, errorInfo: React.ErrorInfo) {
@@ -24,7 +31,12 @@ class ErrorBoundary extends Component<ErrorBoundaryProps, ErrorBoundaryState> {
render() {
if (this.state.hasError) {
- return <h1>Something went wrong.</h1>;
+ return <>
+ <h1>Something went wrong.</h1>
+ <pre>
+ {this.state.error?.stack}
+ </pre>
+ </>;
}
return this.props.children;