From 13bca5d95de10c76e95b05beddea20de8cabda61 Mon Sep 17 00:00:00 2001 From: Nolawz Date: Tue, 3 Mar 2026 11:52:14 +0530 Subject: Added search functionality --- src/components/react/ErrorBoundary.tsx | 63 ++++++++++++++++++++++++++++++++++ 1 file changed, 63 insertions(+) create mode 100644 src/components/react/ErrorBoundary.tsx (limited to 'src/components/react/ErrorBoundary.tsx') diff --git a/src/components/react/ErrorBoundary.tsx b/src/components/react/ErrorBoundary.tsx new file mode 100644 index 0000000..4945094 --- /dev/null +++ b/src/components/react/ErrorBoundary.tsx @@ -0,0 +1,63 @@ +import React, { Component } from 'react' +import type { ErrorInfo, ReactNode } from 'react' + +interface Props { + children: ReactNode + fallback?: ReactNode +} + +interface State { + hasError: boolean + error: Error | null +} + +export class ErrorBoundary extends Component { + constructor(props: Props) { + super(props) + this.state = { hasError: false, error: null } + } + + static getDerivedStateFromError(error: Error): State { + return { hasError: true, error } + } + + componentDidCatch(error: Error, errorInfo: ErrorInfo) { + // Log error to console in development + if (import.meta.env.DEV) { + console.error('ErrorBoundary caught an error:', error, errorInfo) + } + // In production, you could send to error tracking service + // Example: Sentry.captureException(error, { contexts: { react: errorInfo } }) + } + + render() { + if (this.state.hasError) { + if (this.props.fallback) { + return this.props.fallback + } + + return ( +
+

+ Something went wrong +

+

+ {this.state.error?.message || 'An unexpected error occurred'} +

+ +
+ ) + } + + return this.props.children + } +} -- cgit v1.2.3