ErrorBoundary
A React error boundary component that catches JavaScript errors in its child components, logs those errors, and displays a fallback UI (if provided).
Example
function Fallback({ resetErrorBoundary }: ErrorBoundaryFallbackProps) {
return (
<div>
<p>Something went wrong!</p>
<button onClick={resetErrorBoundary}>Try again</button>
</div>
)
}
function App() {
return (
<ErrorBoundary blockType="App" fallback={Fallback}>
<MyMainComponent />
</ErrorBoundary>
)
}
ErrorBoundaryFallbackProps
Props passed to the fallback component or function when an error is caught by the ErrorBoundary
.
ErrorBoundaryProps
Props for the ErrorBoundary
component.
ErrorBoundaryState
Internal state for the ErrorBoundary
component, indicating whether an error has occurred.