Skip to content

Provide a RaygunErrorBoundary component for React error handling #228

@velocitysystems

Description

@velocitysystems

Please describe your new feature request

raygun4reactnative provides RaygunClient.sendError(error) for manually reporting caught errors, but there is no built-in React error boundary component. To report errors caught by an error boundary with full context (including componentStack from componentDidCatch), users have to write their own class-based error boundary and manually wire it up to RaygunClient.

Other crash reporting SDKs ship a dedicated error boundary component that handles this automatically.

Describe the solution you'd like

Provide a RaygunErrorBoundary component that implements componentDidCatch, automatically reports errors to Raygun with the component stack trace, and renders a user-supplied fallback UI:

import { RaygunErrorBoundary } from 'raygun4reactnative';

<RaygunErrorBoundary fallback={<MyErrorScreen />}>
  <App />
</RaygunErrorBoundary>

The component would:

  1. Implement componentDidCatch(error, errorInfo) and call RaygunClient.sendError() with the error and errorInfo.componentStack as custom data
  2. Accept a fallback prop (component or render function) for recovery UI
  3. Optionally accept an onError callback for additional handling

Describe alternatives you've considered

Today the workaround is a hand-rolled class component:

class MyErrorBoundary extends Component {
  state = { error: undefined };

  static getDerivedStateFromError(error: Error) {
    return { error };
  }

  componentDidCatch(error: Error, errorInfo: ErrorInfo) {
    RaygunClient.sendError(error);
    // componentStack is lost — sendError doesn't accept it
  }

  render() {
    if (this.state.error) return <FallbackUI />;
    return this.props.children;
  }
}

This works for basic reporting, but sendError doesn't currently accept custom data like the component stack. A first-party component could attach componentStack as structured data on the Raygun error report automatically.

Additional context

This would also pair well with Expo Router. Expo Router's built-in ErrorBoundary export does not implement componentDidCatch (source), so users who want component stack traces in their crash reports need a separate boundary anyway. A RaygunErrorBoundary would fill that gap cleanly.

Metadata

Metadata

Labels

No labels
No labels

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions