Add ErrorBoundary component

This commit is contained in:
Lukas Bauer 2026-03-25 15:00:00 +00:00
parent c5c2cb2f36
commit 81cd5e4f24

View file

@ -0,0 +1,23 @@
import React from 'react';
interface State { hasError: boolean; message: string; }
export class ErrorBoundary extends React.Component<React.PropsWithChildren, State> {
state: State = { hasError: false, message: '' };
static getDerivedStateFromError(err: Error): State {
return { hasError: true, message: err.message };
}
render() {
if (this.state.hasError) {
return (
<div role="alert" style={{ padding: 24, color: 'var(--color-error)' }}>
<h2>Something went wrong</h2>
<pre>{this.state.message}</pre>
</div>
);
}
return this.props.children;
}
}