React error tracking

React error tracking, including what your error boundaries catch

Error boundaries keep your UI alive but swallow the error. ErrorLens records every render error — caught or not — with the component stack, the user's clicks and readable source.

Initialize before rendering

npm install @errorlenshq/browser
main.tsx (React 19)
import * as ErrorLens from "@errorlenshq/browser";
import { createRoot } from "react-dom/client";

ErrorLens.init({ dsn: "https://<key>@errorlens.io/<project-id>", tracesSampleRate: 0.1 });

createRoot(document.getElementById("root")!, {
  // errors caught by your error boundaries
  onCaughtError: (error, info) =>
    ErrorLens.withScope((scope) => {
      scope.setContext("react", { componentStack: info.componentStack });
      ErrorLens.captureException(error);
    }),
}).render(<App />);

React 18: report from your error boundary

class ErrorBoundary extends React.Component {
  state = { failed: false };
  static getDerivedStateFromError() { return { failed: true }; }
  componentDidCatch(error, info) {
    ErrorLens.withScope((scope) => {
      scope.setContext("react", { componentStack: info.componentStack });
      ErrorLens.captureException(error);
    });
  }
  render() { return this.state.failed ? <p>Something went wrong.</p> : this.props.children; }
}

Also captured

  • Uncaught render errors and errors in event handlers and effects
  • Clicks, route changes and API calls as breadcrumbs
  • A transaction per route change in single-page apps
  • Original source lines once you upload source maps

Frequently asked questions

Does it work with React Router?

Yes. Route changes through the History API are recorded as navigation breadcrumbs and, with tracing on, as navigation transactions.

What about React Native?

This SDK is for browsers. React Native apps can use any SDK that speaks the standard error-envelope protocol.

Start tracking errors in minutes

Free hosted plan with 5,000 errors a month, or self-host with no limits. No credit card.