Team Ai
Apppublic

harshapitla/github-actions-analytics

sourceHugging Faceupdated 10mo agoView on Hugging Face
0likes
ErrorBoundary.js23 linesDownload Raw Back to boundaries
1import React from "react";2 3export default class ErrorBoundary extends React.Component {4  constructor(props) {5    super(props);6    this.state = { hasError: false, error: null };7  }8  static getDerivedStateFromError(error) { return { hasError: true, error }; }9  componentDidCatch(error, info) { console.error("ErrorBoundary:", error, info); }10  render() {11    if (this.state.hasError) {12      return (13        <div style={{ padding: 20, background: "#fff4f4", borderRadius: 8 }}>14          <h3 style={{ marginTop: 0, color: "#b71c1c" }}>Something went wrong</h3>15          <pre style={{ whiteSpace: "pre-wrap" }}>{String(this.state.error)}</pre>16          <p className="small">Open console for stack trace.</p>17        </div>18      );19    }20    return this.props.children;21  }22}23