ErrorBoundary
Location: src/components/ErrorBoundary.jsx
Overview
ErrorBoundary is a React class component that catches JavaScript errors during rendering, lifecycle methods, and constructors of its child component tree. When an error occurs, it displays a friendly fallback UI with a page reload button instead of crashing the entire application.
This is the top-level error safety net for CommonPlace. It logs caught errors to the console via componentDidCatch.
Props
| Prop | Type | Required | Default | Description |
|---|---|---|---|---|
children | ReactNode | Yes | -- | The component tree to wrap with error protection |
Key Behaviors
- Error Capture: Uses
getDerivedStateFromErrorto set error state andcomponentDidCatchto log the error and error info. - Fallback UI: Renders a centered message ("Something went wrong") with a "Reload Page" button that calls
window.location.reload(). - Pass-through: When no error has occurred, renders
this.props.childrenunchanged.
Usage
import ErrorBoundary from '@/components/ErrorBoundary';
<ErrorBoundary>
<App />
</ErrorBoundary>
Related
- This component wraps the entire application tree in
main.jsx.
Last updated: 2026-02-07