An Error Boundary in React is a special type of component that catches JavaScript errors anywhere in its child component tree, logs those errors, and displays a fallback UI instead of crashing the whole app .

Key Points:

✅ Line 1


class ErrorBoundary extends React.Component {

You're defining a class component named ErrorBoundary. It extends React.Component, meaning it inherits lifecycle methods like render, componentDidCatch, etc.

This component will act as a boundary to catch JavaScript errors in its child components.


✅ Line 2–5


constructor(props) {
  super(props);
  this.state = { hasError: false };
}


✅ Line 7–9


static getDerivedStateFromError(error) {
  return { hasError: true };
}