feat: add error boundary to the app root

This commit is contained in:
GyDi
2023-06-08 13:50:45 +08:00
committed by GitHub
Unverified
parent f9a68e8b23
commit 6a9745171e
2 changed files with 16 additions and 7 deletions

View File

@@ -3,18 +3,24 @@ import { ErrorBoundary, FallbackProps } from "react-error-boundary";
function ErrorFallback({ error }: FallbackProps) {
return (
<div role="alert">
<p>Something went wrong:(</p>
<div role="alert" style={{ padding: 16 }}>
<h4>Something went wrong:(</h4>
<pre>{error.message}</pre>
<details title="Error Stack">
<summary>Error Stack</summary>
<pre>{error.stack}</pre>
</details>
</div>
);
}
interface BaseErrorBoundaryProps {
interface Props {
children?: ReactNode;
}
export const BaseErrorBoundary: React.FC<BaseErrorBoundaryProps> = (props) => {
export const BaseErrorBoundary = (props: Props) => {
return (
<ErrorBoundary FallbackComponent={ErrorFallback}>
{props.children}