Files
OpenLearnX/frontend/components/ErrorBoundary.tsx
T
2025-07-29 00:13:52 +05:30

27 lines
489 B
TypeScript

// components/ErrorBoundary.tsx
import React from 'react'
class ErrorBoundary extends React.Component {
constructor(props) {
super(props)
this.state = { hasError: false }
}
static getDerivedStateFromError(error) {
return { hasError: true }
}
render() {
if (this.state.hasError) {
return <div>Something went wrong. Please refresh the page.</div>
}
return this.props.children
}
}
// Wrap your app
<ErrorBoundary>
<YourApp />
</ErrorBoundary>