-
Notifications
You must be signed in to change notification settings - Fork 2
Provide a RaygunErrorBoundary component for React error handling #228
Description
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:
- Implement
componentDidCatch(error, errorInfo)and callRaygunClient.sendError()with the error anderrorInfo.componentStackas custom data - Accept a
fallbackprop (component or render function) for recovery UI - Optionally accept an
onErrorcallback 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.