"use client" import React, { type ErrorInfo } from "react" interface ErrorBoundaryProps { children: React.ReactNode fallback: React.ReactNode} interface ErrorBoundaryState { hasError: boolean} class ErrorBoundary extends React.Component<ErrorBoundaryProps, ErrorBoundaryState> { constructor(props: ErrorBoundaryProps) { super(props) this.state = { hasError: false } } static getDerivedStateFromError(_: Error): ErrorBoundaryState { return { hasError: true } } componentDidCatch(error: Error, errorInfo: ErrorInfo) { console.error("Uncaught error:", error, errorInfo) } render() { if (this.state.hasError) { return this.props.fallback } return this.props.children }} export default ErrorBoundary
"use client"
import React, { type ErrorInfo } from "react"
interface ErrorBoundaryProps {
children: React.ReactNode
fallback: React.ReactNode
}
interface ErrorBoundaryState {
hasError: boolean
}
class ErrorBoundary extends React.Component<ErrorBoundaryProps, ErrorBoundaryState> {
constructor(props: ErrorBoundaryProps) {
super(props)
this.state = { hasError: false }
}
static getDerivedStateFromError(_: Error): ErrorBoundaryState {
return { hasError: true }
}
componentDidCatch(error: Error, errorInfo: ErrorInfo) {
console.error("Uncaught error:", error, errorInfo)
}
render() {
if (this.state.hasError) {
return this.props.fallback
}
return this.props.children
}
}
export default ErrorBoundary