parent
3fb493f400
commit
1ce55e4091
2016 changed files with 23595 additions and 15662 deletions
43
components/ErrorBoundary.tsx
Normal file
43
components/ErrorBoundary.tsx
Normal file
|
|
@ -0,0 +1,43 @@
|
|||
'use client'
|
||||
|
||||
import React, { Component, ErrorInfo, ReactNode } from 'react'
|
||||
|
||||
interface Props {
|
||||
children?: ReactNode
|
||||
}
|
||||
|
||||
interface State {
|
||||
hasError: boolean
|
||||
}
|
||||
|
||||
export class ErrorBoundary extends Component<Props, State> {
|
||||
public state: State = {
|
||||
hasError: false
|
||||
}
|
||||
|
||||
public static getDerivedStateFromError(_: Error): State {
|
||||
return { hasError: true }
|
||||
}
|
||||
|
||||
public componentDidCatch(error: Error, errorInfo: ErrorInfo) {
|
||||
console.error('Uncaught error:', error, errorInfo)
|
||||
}
|
||||
|
||||
public render() {
|
||||
if (this.state.hasError) {
|
||||
return (
|
||||
<div className="p-4 text-red-500">
|
||||
<h2>Something went wrong.</h2>
|
||||
<button
|
||||
className="mt-2 px-4 py-2 bg-red-100 rounded"
|
||||
onClick={() => this.setState({ hasError: false })}
|
||||
>
|
||||
Try again
|
||||
</button>
|
||||
</div>
|
||||
)
|
||||
}
|
||||
|
||||
return this.props.children
|
||||
}
|
||||
}
|
||||
8
components/ErrorBoundaryWrapper.tsx
Normal file
8
components/ErrorBoundaryWrapper.tsx
Normal file
|
|
@ -0,0 +1,8 @@
|
|||
'use client'
|
||||
|
||||
import { ReactNode } from 'react'
|
||||
import { ErrorBoundary } from './ErrorBoundary'
|
||||
|
||||
export function ErrorBoundaryWrapper({ children }: { children: ReactNode }) {
|
||||
return <ErrorBoundary>{children}</ErrorBoundary>
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue