Files
compor-academy/components/ui/ErrorBoundary.tsx
Cauê Faleiros fff63f5efa
All checks were successful
CI / Validate frontend and API (push) Successful in 59s
CI / Build and publish Docker images (push) Successful in 23s
feat: add reviews, notifications, notes and account hardening
2026-11-05 17:27:36 -03:00

32 lines
982 B
TypeScript

import React, { ReactNode } from 'react';
interface ErrorBoundaryState {
hasError: boolean;
}
export class ErrorBoundary extends React.Component<{ children: ReactNode }, ErrorBoundaryState> {
declare props: Readonly<{ children: ReactNode }>;
state: ErrorBoundaryState = { hasError: false };
static getDerivedStateFromError(): ErrorBoundaryState {
return { hasError: true };
}
componentDidCatch(error: Error, info: React.ErrorInfo) {
console.error('Unhandled application error', error, info);
}
render() {
if (this.state.hasError) {
return <main className="wrap page">
<div className="empty">
<h1>Algo deu errado</h1>
<p>Não foi possível exibir esta página. Recarregue para tentar novamente.</p>
<button className="btn" type="button" onClick={() => window.location.reload()} style={{ marginTop: 20 }}>Recarregar página</button>
</div>
</main>;
}
return this.props.children;
}
}