Use await block to wait for a promise and handle loading state in Svelte 3

Share this video with your friends

Send Tweet

Most web applications have to deal with asynchronous data at some point.

Svelte 3 apps are no different, luckily Svelte allows us to await the value of a promise directly in markup using await block.

In this lesson we're going to learn how to use the await block to fetch the data from a Star Wars API and both display the data and handle loading state.

Frederik
Frederik
~ 3 years ago

This API is no longer available...

I'm having some trouble finding a replacement. I'm currently using fakeapi.jsonparseronline.com , e.g. this endpoint:

http://fakeapi.jsonparseronline.com/users

Lucas Minter
Lucas Minter
~ 3 years ago

This API is no longer available...

The api has changed from a .co to a .dev. Use this link instead: https://swapi.dev/api/people/

Frederik
Frederik
~ 3 years ago

Thanks for letting me know!