window.onerror — a thrown error inside a render function or lifecycle method is caught by React’s own reconciler and never reaches the global handler. The only reliable hook React exposes is the class component lifecycle method componentDidCatch. <ArgusErrorBoundary> wraps that lifecycle into a drop-in component you can place around your component tree. Because the React SDK re-exports everything from @argusdev/sdk-browser, you get automatic capture of all unhandled browser errors — plus render-crash reporting — from a single import.
Installation
Initialization
Import
init from @argusdev/sdk-react and call it before rendering your root component. This registers the window.onerror and unhandledrejection handlers that capture all non-render errors alongside your boundary.import { init } from '@argusdev/sdk-react';
init({
dsn: 'https://YOUR_PUBLIC_KEY@your-domain.com/YOUR_PROJECT_ID',
environment: 'production',
release: '1.0.0',
});
export interface InitOptions {
/** Your project DSN (required). Format: https://PUBLIC_KEY@host/PROJECT_ID */
dsn: string;
/** The environment name shown in Argus (e.g. 'production', 'staging'). */
environment?: string;
/** Your application's release version (e.g. '1.4.2' or a git SHA). */
release?: string;
}
ArgusErrorBoundary
Wrap your root component (or any subtree you want to protect) with<ArgusErrorBoundary>. When a render error occurs inside the boundary, componentDidCatch calls captureException with the error and attaches the crashing component’s name as a tag.
Props
| Prop | Type | Required | Description |
|---|---|---|---|
children | ReactNode | — | The component subtree to monitor for render errors. |
fallback | ReactNode | — | What to render after a crash. Defaults to rendering nothing (null) if omitted. |
How it works
When a render error propagates up to the boundary, React calls two methods in sequence:getDerivedStateFromError()— setshasError: trueso the boundary re-renders and displays yourfallback.componentDidCatch(error, info)— callscaptureException(error)and attaches the first line of React’scomponentStackas a tag namedcomponentStack. That first line is the name of the component that threw, giving you an immediate pointer in Argus without needing to read the full stack trace.
Protecting multiple subtrees
You can nest multiple boundaries to give different parts of your UI independent fallback behavior. Only the subtree inside a boundary is unmounted on a crash — the rest of your app continues running.Why a Boundary?
React intercepts render errors inside its reconciler before they reach the browser’s global
window.onerror handler. In production builds, a component that throws during render produces no global error event — without a boundary, the crash is invisible to any global monitoring tool. componentDidCatch is the only lifecycle hook React provides for observing these crashes, and it is only available on class components. <ArgusErrorBoundary> is that class component.Exported API
@argusdev/sdk-react re-exports everything from @argusdev/sdk-browser, so you never need to install or import from both packages.
| Symbol | Kind | Description |
|---|---|---|
init | function | Initializes the SDK and registers global browser error handlers. Re-exported from @argusdev/sdk-browser. |
captureException | function | Manually captures and sends an exception. Re-exported from @argusdev/sdk-browser. |
ArgusErrorBoundary | class component | React error boundary that captures render crashes. |
InitOptions | interface | TypeScript type for the init() options object. Re-exported from @argusdev/sdk-browser. |