Skip to main content

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 the errorElement prop directly on the <Await> component or handling errors in your loader/action functions.

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 errorElement prop on <Await> or handle errors in your loader/action instead
  • This hook must be used within a component rendered by an <Await> component’s errorElement
  • Available in Framework and Data modes only
  • The returned error is unknown by 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)