'use client'; import React from 'react'; interface State { hasError: boolean; error: Error | null; } interface Props { children: React.ReactNode; fallback?: React.ReactNode; } export class ErrorBoundary extends React.Component { constructor(props: Props) { super(props); this.state = { hasError: false, error: null }; } static getDerivedStateFromError(error: Error): State { return { hasError: true, error }; } componentDidCatch(error: Error, info: React.ErrorInfo) { console.error('[ErrorBoundary]', error, info.componentStack); } render() { if (this.state.hasError) { if (this.props.fallback) return this.props.fallback; return (

Đã xảy ra lỗi hiển thị.

{this.state.error?.message}

); } return this.props.children; } }