astock-agent/frontend/src/components/error-boundary.tsx
2026-04-16 14:16:02 +08:00

37 lines
899 B
TypeScript

"use client";
import { Component, ReactNode } from "react";
interface Props {
children: ReactNode;
fallback?: ReactNode;
}
interface State {
hasError: boolean;
}
export class ErrorBoundary extends Component<Props, State> {
state: State = { hasError: false };
static getDerivedStateFromError(): State {
return { hasError: true };
}
render() {
if (this.state.hasError) {
return this.props.fallback || (
<div className="glass-card-static p-8 text-center">
<div className="text-sm text-red-400 mb-2"></div>
<button
onClick={() => this.setState({ hasError: false })}
className="text-xs px-3 py-1.5 bg-surface-2 rounded-lg text-text-secondary hover:text-text-primary transition-all"
>
</button>
</div>
);
}
return this.props.children;
}
}