Files
aicyclingcoach-go/frontend/src/components/ErrorBoundary.jsx
T
2025-09-09 06:04:29 -07:00

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;