feat(web): wrap app in errorboundary

Prevents the app from failing on render errors as mentioned
in #675. More to come..
This commit is contained in:
Linden
2024-12-06 17:25:34 +11:00
parent 4d7fee41bd
commit aebef6d7de
2 changed files with 33 additions and 6 deletions

View File

@@ -0,0 +1,23 @@
import { Component, ReactNode, ErrorInfo } from 'react';
class ErrorBoundary extends Component<{ children: ReactNode }, { hasError: boolean }> {
constructor(props: { children: ReactNode }) {
super(props);
this.state = { hasError: false };
}
static getDerivedStateFromError(err: Error) {
return { hasError: true };
}
componentDidCatch(error: Error, info: ErrorInfo) {
console.error(error, info)
this.setState({ hasError: false });
}
render() {
return this.state.hasError ? null : this.props.children;
}
}
export default ErrorBoundary;