analytics / assets /js /dashboard /error /error-boundary.tsx
Leon4gr45's picture
Upload folder using huggingface_hub
b2a00c5 verified
Raw
History Blame Contribute Delete
678 Bytes
import React, { ReactNode, ReactElement } from 'react'
type ErrorBoundaryProps = {
children: ReactNode
renderFallbackComponent: (props: { error?: unknown }) => ReactElement
}
type ErrorBoundaryState = { error: null | unknown }
export default class ErrorBoundary extends React.Component<
ErrorBoundaryProps,
ErrorBoundaryState
> {
constructor(props: ErrorBoundaryProps) {
super(props)
this.state = { error: null }
}
static getDerivedStateFromError(error: unknown) {
return { error }
}
render() {
if (this.state.error) {
return this.props.renderFallbackComponent({ error: this.state.error })
}
return this.props.children
}
}