Files
ColdBreeze-chat-web/src/components/ErrorCatcher.tsx
T
Tristan Yang 2150213a25 chore: updates
2023-08-01 18:20:00 +08:00

29 lines
773 B
TypeScript

import { ReactNode } from "react";
import { ErrorBoundary } from "react-error-boundary";
import StyledButton from "./styled/Button";
type FallbackProps = {
error: Error;
resetErrorBoundary: (...args: Array<unknown>) => void;
};
function ErrorFallback({ error, resetErrorBoundary }: FallbackProps) {
return (
<div role="alert" className="text-lg text-red-600">
<p>Something went wrong:</p>
<pre>{error.message}</pre>
<StyledButton className="mini" onClick={resetErrorBoundary}>
Try again
</StyledButton>
</div>
);
}
type Props = {
children: ReactNode;
};
const ErrorCatcher = ({ children }: Props) => {
return <ErrorBoundary FallbackComponent={ErrorFallback}>{children}</ErrorBoundary>;
};
export default ErrorCatcher;