Overview
TheSuspenseWithBoundary component combines React Suspense with an ErrorBoundary, providing a convenient way to handle both loading states and errors in a single component.
Import
Props
React.ReactNode
required
The content to render with suspense and error boundary protection.
React.ReactNode
Fallback UI to display while suspended (loading state).
React.ReactNode | ((props: ErrorFallbackProps) => React.ReactNode)
Fallback UI to display when an error occurs. Can be a component or render function.
Type Definitions
Usage Examples
Basic Usage
With Error Details
Data Fetching
Nested Loading States
Minimal Configuration
Server Components
Multiple Async Resources
Notes
- This component is a convenience wrapper around
ErrorBoundaryandSuspense - The ErrorBoundary wraps the Suspense component
- If
errorFallbackis not provided, the ErrorBoundary still catches errors but won’t display a fallback - If
fallbackis not provided, Suspense will use React’s default behavior - Works with React Server Components and client components
- Useful for data fetching with libraries that support Suspense (React Query, SWR, etc.)