Skip to main content
The Sentry React SDK extends the Browser SDK with React-specific features including ErrorBoundary, Profiler components, and React Router integrations.

Installation

Basic Setup

Initialize Sentry before mounting your React application:

React 19 Error Handling

Starting with React 19, use the new error hooks for automatic error capture:

ErrorBoundary Component

Catch React component errors and display fallback UI:

Profiler Component

Track React component render performance:

React Router Integration

Sentry supports all major versions of React Router:

TanStack Router Integration

For TanStack Router (formerly React Location):

Redux Integration

Create a Sentry Redux enhancer:

Performance Monitoring

Component Tracking

Custom Spans

ErrorBoundary Configuration

The ErrorBoundary component accepts these props:
  • fallback: React element or render function to display when error occurs
  • showDialog: Show Sentry user feedback dialog
  • dialogOptions: Options for the feedback dialog
  • onError: Callback when error is caught
  • onReset: Callback when error boundary is reset
  • onMount: Callback on component mount
  • onUnmount: Callback on component unmount
  • beforeCapture: Modify scope before error is sent
  • handled: Override whether error is marked as handled

Best Practices

Multiple Boundaries

Use multiple ErrorBoundary components at different levels of your component tree.

Profile Wisely

Only wrap components where you need render performance data.

Router Integration

Always use router integrations for accurate transaction names.

User Feedback

Enable showDialog to collect user feedback on errors.

Next Steps

React Router

Set up router performance tracking

Redux

Integrate with state management

Error Boundaries

Advanced error boundary patterns

Profiling

Component performance profiling