ErrorBoundary
TheErrorBoundary component catches React errors anywhere in the child component tree, logs those errors, and displays a friendly fallback UI instead of crashing the entire widget.
Import
Props
| Prop | Type | Default | Description |
|---|---|---|---|
children | React.ReactNode | required | The widget content to wrap |
Basic Usage
Automatic Inclusion
ErrorBoundary is automatically included when using McpUseProvider:
Error Display
When an error occurs, the boundary displays:- A red-bordered error container
- The error message in a readable format
- Dark mode support (adapts to theme)
Error Logging
Errors are automatically logged to the console with:- The error object
- React error info (component stack, etc.)
Best Practices
- Use McpUseProvider: For most cases, use
McpUseProviderwhich includesErrorBoundaryautomatically - Wrap at widget level: Wrap your entire widget, not individual components
- Handle errors gracefully: Consider what fallback UI makes sense for your widget
Example: Custom Error Handling
If you need custom error handling, you can wrap specific parts:Related Components
McpUseProvider- Includes ErrorBoundary automaticallyuseWidget- Widget hook for accessing props and actions