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

Should I access the api directly inside the script tag in a svelte SPA?

$
0
0

I am writing a Svelte CSR application. I am wondering whether this is ok:

<script>    const data = api.getDataAsync()<script>{#await data}<span>Loading</span>{:then data}   //display data{/await}

If not why? should I do it the react way

<script>      let data = $state(undefined)   onMount(()=>{       api.getDataSync().then(apiData=>data=apiData)   })</script>{#if !data}<span>loading...</span>{:else}   //display data{/if}

Edit: Because I am using PocketBase, I have SSR turned off.


Viewing all articles
Browse latest Browse all 1545

Trending Articles



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