javascript / beginner
Snippet
The {#await} Block
The `{#await}` block is a clean way to handle asynchronous data directly in your HTML. It lets you define different states for the promise: pending (loading), fulfilled (success), and rejected (error).
snippet.js
1
2
3
4
5
6
7
{#await promise}<p>Loading...</p>{:then data}<p>Success: {data}</p>{:catch error}<p>Error: {error.message}</p>{/await}
svelte
Breakdown
1
{#await promise}
Begins the block and shows the content until the promise resolves or rejects.
2
{:then data}
This section renders once the promise successfully resolves, providing the result as 'data'.