Quantcast
Channel: Active questions tagged svelte - Stack Overflow
Viewing all articles
Browse latest Browse all 1879

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>{#if data?.value}<pre>data is {data.value}</pre>{:else}<pre>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 1879

Trending Articles



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