DEV Community

Cover image for Fetching Data in Svelte

Fetching Data in Svelte

David on February 17, 2021

I always find it frustrating when I'm learning a new framework and I get to the point where I have to depart from my existing knowledge and princip...
Collapse
 
stefanovualto profile image
stefanovualto

Hi David,

Using a promise to fetch, you could use await blocks.

Have a look at this: svelte.dev/tutorial/await-blocks

Collapse
 
jrmoynihan profile image
jrmoynihan

Agreed. {#await...then...catch} is the preferred way to do this, especially considering the fetch is already within an async function, which will return a promise.

Collapse
 
mauro_codes profile image
Mauro Garcia

I really appreciate that I don't need to learn "the svelty way" for fetching data. You explained it very well, David!

I just wanted to add that on more complex scenarios; It could be a good alternative to handle all the data fetching on services to reuse functions from different components.

Great post! We need more people sharing their experiences with Svelte!

Collapse
 
daveturissini profile image
David

Totally agree! In a more complex scenario, i think you want to completely separate data calls from components.

Collapse
 
torstendittmann profile image
Torsten Dittmann

You could also just use await blocks offered by Svelte :)

Collapse
 
daveturissini profile image
David

Very cool! I haven’t had a chance to use these yet

Collapse
 
amensouissi profile image
Amen SOUISSI
Collapse
 
kovarpavel profile image
Pavel Kovar

Very good examples, Thanks for this article.

Collapse
 
daveturissini profile image
David

Thanks Pavel!

Collapse
 
kalashin1 profile image
Kinanee Samson

Nice one bro

Collapse
 
daveturissini profile image
David • Edited

Thanks Kinanee