@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 Current Version: 10.42.0
@sentry/react using your preferred package manager: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:
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: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:-
Install the Webpack plugin:
-
Configure in
webpack.config.js:
Error Boundaries Not Working
Make sure:- You’re using a class component or the Sentry
ErrorBoundary - The error is thrown during render, not in event handlers
- For event handler errors, use
try/catchwithSentry.captureException()
Next Steps
- Configure React Router Integration
- Set up Redux Integration
- Learn about Session Replay
- Explore Performance Monitoring