import { Component, type ReactNode } from "react"
import { useLocale } from "./i18n"
function ErrorFallback({ error, onRetry }: { error: Error; onRetry: () => void }) {
const { t } = useLocale()
return (
{t("error.title")}
{t("error.hint")}
{String(error)}
)
}
interface State { error: Error | null; stack: string }
export class ErrorBoundary extends Component<{ children: ReactNode }, State> {
state: State = { error: null, stack: "" }
static getDerivedStateFromError(error: Error): Partial { return { error } }
componentDidCatch(error: Error, info: { componentStack?: string }) {
console.error("[colibrì] render crash:", error, info.componentStack)
this.setState({ stack: info.componentStack ?? "" })
}
render() {
if (!this.state.error) return this.props.children
return this.setState({ error: null, stack: "" })} />
}
}