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:- Basic Usage
- Custom Fallback
- HOC Pattern
Profiler Component
Track React component render performance:- withProfiler HOC
- Profiler Component
- useProfiler Hook
React Router Integration
Sentry supports all major versions of React Router:- React Router v6
- React Router v5
- React Router v4
TanStack Router Integration
For TanStack Router (formerly React Location):Redux Integration
Create a Sentry Redux enhancer:Performance Monitoring
Component Tracking
Custom Spans
ErrorBoundary Configuration
ErrorBoundary Props
ErrorBoundary Props
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