Overview
TheAwait component provides a declarative way to handle asynchronous operations in React, with built-in support for Suspense and Error Boundaries. It automatically manages loading, success, and error states.
Import
Component Parts
Await.Root
The root component that wraps the promise handling logic
Await.Success
Renders when the promise resolves successfully
Await.Error
Renders when the promise rejects with an error
Await.Pending
Renders while the promise is pending
Await.Root
Props
Promise<TValue>
required
The promise to await and resolve.
React.ReactNode | ((result: TValue) => React.ReactNode)
required
The content to render on success. Can be a render function that receives the resolved value.
React.ReactNode
Fallback UI to display while the promise is pending (used with Suspense).
React.ReactNode | ((props: ErrorFallbackProps) => React.ReactNode)
Fallback UI to display when the promise rejects (used with ErrorBoundary).
boolean
default:"true"
Whether to wrap the component with React Suspense.
boolean
default:"true"
Whether to wrap the component with an ErrorBoundary.
boolean
When true, merges props into the child element instead of rendering a wrapper.
Await.Success
Props
React.ReactNode | ((result: TValue) => React.ReactNode)
required
The content to render when the promise resolves. Can be a render function that receives the resolved value.
Await.Error
Props
React.ReactNode | ((context: ErrorBoundaryContextType) => React.ReactNode)
required
The content to render when an error occurs. Can be a render function that receives error context.
boolean
When true, merges props into the child element instead of rendering a wrapper.
Await.Pending
Props
React.ReactNode
required
The content to display while the promise is pending.
Hook
useAwaitContext
Promise<TValue>
The original promise passed to Await.Root.
TValue
The resolved value of the promise.