Source identity
| Field | Recorded value |
|---|---|
| Source type | GitHub source |
| Original record | Janady13/llms-txt-hub / packages/design-system/components/custom/error-boundary.tsx |
| Date | Not specified in source |
| Repository | Janady13/llms-txt-hub |
| Revision | e0f4bf978d4df168369c7601d9c5f5ea89e84377 |
| Branch | main |
| Path or archive member | packages/design-system/components/custom/error-boundary.tsx |
| Original SHA-256 | eb88eeddc4c7dda7901a1ef10a0db0f243d40509e83efa400a5336d566e34c81 |
| Git blob SHA | 4cec3bd8ce1a121acbefce2fad49e2c1c3d61895 |
| Reading-copy SHA-256 | eb88eeddc4c7dda7901a1ef10a0db0f243d40509e83efa400a5336d566e34c81 |
Recovered source transcript
Download complete source text ↓42 lines · 0.9 KB
import type { ErrorInfo, ReactNode } from 'react'
import { Component } from 'react'
interface Props {
onError?: (error: Error, info: ErrorInfo) => void
fallback: ReactNode
children: ReactNode
}
interface State {
hasError: boolean
error?: Error
}
export class ErrorBoundary extends Component<Props, State> {
readonly state: State = { hasError: false }
// biome-ignore lint/complexity/noUselessConstructor: React component needs constructor for proper initialization
constructor(props: Props) {
super(props)
}
static getDerivedStateFromError(error: Error): State {
return {
hasError: true,
error
}
}
componentDidCatch(error: Error, info: ErrorInfo) {
this.props.onError?.(error, info)
}
render() {
if (this.state.hasError) {
return this.props.fallback || <div>Something went wrong</div>
}
return this.props.children
}
}