mirror of
https://github.com/sstent/aicyclingcoach-go.git
synced 2026-06-06 02:44:00 +00:00
30 lines
695 B
React
30 lines
695 B
React
import React from 'react';
|
|
|
|
class ErrorBoundary extends React.Component {
|
|
constructor(props) {
|
|
super(props);
|
|
this.state = { hasError: false, error: null };
|
|
}
|
|
|
|
static getDerivedStateFromError(error) {
|
|
return { hasError: true, error };
|
|
}
|
|
|
|
componentDidCatch(error, errorInfo) {
|
|
console.error('Error caught by boundary:', error, errorInfo);
|
|
}
|
|
|
|
render() {
|
|
if (this.state.hasError) {
|
|
return (
|
|
<div className="p-4 bg-red-50 text-red-700 rounded-lg">
|
|
<h2 className="font-bold">Something went wrong</h2>
|
|
<p>{this.state.error.message}</p>
|
|
</div>
|
|
);
|
|
}
|
|
return this.props.children;
|
|
}
|
|
}
|
|
|
|
export default ErrorBoundary; |