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
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
- Handle all states - Always consider pending, success, and error states
- Provide feedback - Show loading indicators during async operations
- Error recovery - Offer retry mechanisms for failed requests
- Avoid cascading promises - Combine related data fetching when possible
- Consider SSR - Remember that only pending state renders on the server