When to Use
- Display loading states while data is being fetched
- Handle errors from async operations gracefully
- Show different UI based on promise resolution state
- Avoid manual promise handling with useState and useEffect
- Integrate with React Suspense and Error Boundaries automatically
Basic Usage
Component API
Await.Root
The root component that manages the promise lifecycle.Promise<TValue>
required
The promise to await and resolve
React.ReactNode | ((result: TValue) => React.ReactNode)
required
Content to render on success. Can be a render function receiving the resolved value
React.ReactNode
Fallback UI to show while the promise is pending (passed to Suspense)
React.ReactNode | ((props: ErrorFallbackProps) => React.ReactNode)
Fallback UI to show when the promise rejects (passed to ErrorBoundary)
boolean
default:"true"
Whether to wrap children with React Suspense
boolean
default:"true"
Whether to wrap children with ErrorBoundary
boolean
Merge props into the child element instead of rendering a wrapper
Await.Success
Renders content when the promise resolves successfully.React.ReactNode | ((result: TValue) => React.ReactNode)
required
Content to render. Can be a render function receiving the resolved value
Await.Error
Renders content when the promise rejects.React.ReactNode | ((context: ErrorBoundaryContext) => React.ReactNode)
required
Content to render on error. Render function receives error and resetErrorBoundary
boolean
Merge props into the child element
Await.Pending
Renders content while the promise is pending.React.ReactNode
required
Loading UI to display
Advanced Examples
Using Inline Props
Disabling Suspense/ErrorBoundary
Using asChild for Prop Merging
Comparison to Native Patterns
Traditional Approach
With Await Component
The Await component uses React’s
use hook internally to unwrap promises, automatically integrating with Suspense boundaries for optimal loading states.