MCPcopy Create free account
hub / github.com/code100x/daily-code / ErrorBoundary

Class ErrorBoundary

apps/web/components/ErrorBoundary.tsx:11–34  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

9}
10
11export class ErrorBoundary extends Component<ErrorBoundaryProps, ErrorBoundaryState> {
12 constructor(props: ErrorBoundaryProps) {
13 super(props);
14 this.state = { hasError: false };
15 }
16
17 static getDerivedStateFromError() {
18 // Update state so the next render will show the fallback UI.
19 return { hasError: true };
20 }
21
22 componentDidCatch(error: Error, errorInfo: React.ErrorInfo) {
23 console.log(error, errorInfo);
24 }
25
26 render() {
27 if (this.state.hasError) {
28 // You can render any custom fallback UI
29 return <h1>Something went wrong.</h1>;
30 }
31
32 return this.props.children;
33 }
34}

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected