Skip to main content
The @sentry/react package provides error tracking, performance monitoring, and React-specific features like Error Boundaries and component profiling.

Prerequisites

  • Node.js 18 or newer
  • React 16.14.0, 17.x, 18.x, or 19.x
  • A Sentry account and project DSN

Installation

1

Install the Package

Install @sentry/react using your preferred package manager:
Current Version: 10.42.0
2

Initialize Sentry

Initialize Sentry before you mount your React component. This should be done as early as possible:
3

Verify Installation

Test that Sentry is working:
Check your Sentry dashboard to see the error.

React 19 Error Handling

Starting with React 19, createRoot and hydrateRoot expose error hooks that can be used to capture errors automatically:
For finer-grained control, use only the onUncaughtError and onRecoverableError hooks, and use an ErrorBoundary component instead of the onCaughtError hook.

Error Boundary

The @sentry/react package exports an ErrorBoundary component that automatically captures JavaScript errors from inside a component tree and displays a fallback UI:

Error Boundary Options

Multiple Error Boundaries

You can use multiple error boundaries to isolate different parts of your app:

React Profiler

The Profiler component tracks component lifecycle performance:
Or wrap an entire component with the HOC:
The Profiler requires tracing to be enabled. If tracing is not enabled, the Profiler will not work.

React Router Integration

React Router v6

React Router v5 and v4

Usage

Capturing Errors

Setting Context

Adding Breadcrumbs

Custom Spans

Performance Monitoring

Basic Configuration

With React Router

Session Replay

Capture session replays to see what users experienced:

Privacy Options

Advanced Configuration

TypeScript

The SDK is written in TypeScript and includes type definitions:

Redux Integration

Next Steps After Errors

Troubleshooting

Source Maps

For production builds with Webpack:
  1. Install the Webpack plugin:
  2. Configure in webpack.config.js:
For Vite:

Error Boundaries Not Working

Make sure:
  1. You’re using a class component or the Sentry ErrorBoundary
  2. The error is thrown during render, not in event handlers
  3. For event handler errors, use try/catch with Sentry.captureException()
Error Boundaries do not catch errors in:
  • Event handlers (use try/catch instead)
  • Asynchronous code (setTimeout, promises)
  • Server-side rendering
  • Errors thrown in the Error Boundary itself

Next Steps