useAsyncError
Returns the rejection value from the closest <Await> component.
Return Value
unknown
The error that was thrown in the nearest
<Await> component when its promise was rejected. The type will match whatever error was thrown.Type Declaration
Deprecation Notice
This hook is deprecated in favor of using theerrorElement prop directly on the <Await> component or handling errors in your loader/action functions.
Recommended Alternatives
Use errorElement Prop
Handle Errors in Loader
Usage Examples (Legacy)
Basic Error Handling
Detailed Error Information
Error with Retry
Type Safety
Error Type Guards
Notes
- Deprecated: Use
errorElementprop on<Await>or handle errors in your loader/action instead - This hook must be used within a component rendered by an
<Await>component’serrorElement - Available in Framework and Data modes only
- The returned error is
unknownby default - use type assertions or type guards for type safety - The error is only available when the promise rejects
Migration Guide
Before (using useAsyncError)
After (using errorElement directly)
Or (handle in loader)
Related
useAsyncValue- Get the resolved value from Await<Await>- Component for rendering deferred datauseRouteError- Get errors from loaders/actions- Error Handling Guide - Learn about error handling in React Router