shared/ErrorBoundary.tsx

ai-engineering-hub · open-agent-builder/components/shared/ErrorBoundary.tsx · typescript · MIT
ui

Module exposing: ErrorBoundary

// Source: https://github.com/patchy631/ai-engineering-hub | License: MIT | Copyright 2024 patchy631
// Provided via justclaw.it.com; keep this notice with the code.
import { Component, ReactNode } from 'react';

interface ErrorBoundaryProps {
  children: ReactNode;
  fallback?: ReactNode;
  onError?: (error: Error, errorInfo: React.ErrorInfo) => void;
}

interface ErrorBoundaryState {
  hasError: boolean;
  error?: Error;
}

/**
 * Error Boundary component to catch React errors and prevent full app crashes.
 *
 * Usage:
 * ```tsx
 * <ErrorBoundary>
 *   <YourComponent />
 * </ErrorBoundary>
 * ```
 *
 * With custom fallback:
 * ```tsx
 * <ErrorBoundary fallback={<div>Custom error UI</div>}>
 *   <YourComponent />
 * </ErrorBoundary>
 * ```
 */
export class ErrorBoundary extends Component<

... (truncated -- full source via MCP)

See the full source, get the GitHub permalink, and search for more like it.

Get a free API key