Skip to main content
Await blocks let you branch on the three possible states of a Promise - pending, fulfilled, or rejected.

Full Await Block

Handle all three Promise states:

Example

Without Catch Block

Omit error handling if no error is possible or you don’t need to show error state:

Example

Then Only

Skip the pending state when you only care about the result:

Example

Catch Only

Show only the error state:

Example

Real-World Use Cases

API Data Fetching

Lazy Component Loading

Search Results

File Upload

Server-Side Rendering

During server-side rendering, only the pending branch will be rendered. If the expression is not a Promise, only the :then branch will be rendered (including during SSR).

Progressive Enhancement Pattern

Combining with Each Blocks

Dynamic Promises

The await block re-evaluates when the promise expression changes:

Best Practices

  1. Handle all states - Always consider pending, success, and error states
  2. Provide feedback - Show loading indicators during async operations
  3. Error recovery - Offer retry mechanisms for failed requests
  4. Avoid cascading promises - Combine related data fetching when possible
  5. Consider SSR - Remember that only pending state renders on the server