resume / src /ErrorBoundary.js
satishsnv
initial commit
736e3f5
Raw History Blame Contribute Delete
965 Bytes
import React from 'react';
import './App.css';
class ErrorBoundary extends React.Component {
constructor(props) {
super(props);
this.state = { hasError: false };
}
static getDerivedStateFromError(error) {
return { hasError: true };
}
componentDidCatch(error, errorInfo) {
console.error('ErrorBoundary caught an error:', error, errorInfo);
}
render() {
if (this.state.hasError) {
return (
<div className="error-container">
<h1 className="error-title">🚀 Oops!</h1>
<p className="error-text">
Something went wrong with Satish's portfolio. Don't worry, this rarely happens!
Please try refreshing the page or come back later.
</p>
<button className="retry-button" onClick={() => window.location.reload()}>
Refresh Page
</button>
</div>
);
}
return this.props.children;
}
}
export default ErrorBoundary;