Skip to main content

ErrorBoundary

A React component that renders when an error is thrown in a route’s loader, action, or component.

Signature

The ErrorBoundary is a React component with no props. It uses the useRouteError() hook to access the error that was thrown.

Basic Example

Handling Different Error Types

Nested Error Boundaries

Error boundaries bubble up to the nearest parent route with an ErrorBoundary export:

With Loader Data

Resetting Errors

Throwing Errors in Components

Custom Error Data

Best Practices

Use Response objects for errors that are part of normal app flow:
Don’t catch unexpected errors - let them reach ErrorBoundary:
Give users actionable information:
Always provide a root-level ErrorBoundary:

See Also