Quantcast
Channel: Recent Questions - Stack Overflow
Viewing all articles
Browse latest Browse all 12111

How to get data loaded asyncronosly from load functions of SvelteKit?

$
0
0

I am new to Svelte and want to do something like this in my +page.js:

export async function load() {    let prom = new Promise((res) => {        setTimeout(() => res('myData'), 10000)    })    let value = await prom    return {        value    }}

And the following is my +page.svelte:

<script>    export let data</script>{#await data.value}<pre>data is Loading...</pre>{:then value}<pre>data is {'value'}</pre>{:catch error}<p>error loading comments: {error.message}</p>{/await}data is Loading...</pre>{/if}

But, I am not getting the :else part on my page at all. Instead, the entire page keeps loading for a whole 10sec and then flashes the data value directly. How can I achieve the expected?


Viewing all articles
Browse latest Browse all 12111

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>