Loading files
This file is pinned to the selected release. Download the original to open it in your design tool.
'use client'
import { Component, type ReactNode } from 'react'
interface Props {
children: ReactNode
fallback?: ReactNode
}
interface State {
hasError: boolean
error: Error | null
}
export class ErrorBoundary extends Component<Props, State> {
constructor(props: Props) {
super(props)
this.state = { hasError: false, error: null }
}
static getDerivedStateFromError(error: Error): State {
return { hasError: true, error }
}
componentDidCatch(error: Error, errorInfo: React.ErrorInfo) {
console.error('[ErrorBoundary]', error, errorInfo)
}
render() {
if (this.state.hasError) {
if (this.props.fallback) return this.props.fallback
return (
<div className="flex flex-col items-center justify-center h-full p-8 text-center">
<h2 className="text-lg font-semibold text-[var(--app-text-primary)] mb-2">Something went wrong</h2>
<p className="text-sm text-[var(--app-text-muted)] mb-4 max-w-md">
{this.state.error?.message || 'An unexpected error occurred'}
</p>
<button
onClick={() => this.setState({ hasError: false, error: null })}
className="px-4 py-2 text-sm rounded-md bg-[var(--app-accent)] text-white hover:opacity-90"
>
Try again
</button>
</div>
)
}
return this.props.children
}
}
e934a3ad8This file is pinned to the selected release. Download the original to open it in your design tool.