1 Answer
- Newest
- Most votes
- Most comments
0
import React from 'react';
class ErrorBoundary extends React.Component {
constructor(props) {
super(props);
this.state = { hasError: false };
}
static getDerivedStateFromError(error) {
return { hasError: true };
}
componentDidCatch(error, info) {
// Log error details to an error reporting service
console.error("ErrorBoundary caught an error", error, info);
}
render() {
if (this.state.hasError) {
return <h1>Something went wrong.</h1>;
}
return this.props.children;
}
}
export default ErrorBoundary;
answered a year ago
Relevant content
- asked 4 years ago
- AWS OFFICIALUpdated 3 years ago
