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

Nice way to load data in-time with Svelte

$
0
0

In Svelte, we have a very nice and beautiful way to load some data in time and render it using @const:

<script>    let a = false;</script><button on:click={() => a = !a}></button>{#if a}    {@const table = axios.get(...)}    {#await table}<Spinner />    {:then table}        ...    {/await} {/if}

This way, we don't really have to declare anything in the body. But sometimes we might need to have some logic inside:

{@const table = axios.get(...)}{#await table}<Spinner />{:then table}    {#each table as x}<button on:click={() => x.open = true}>            Open row!</button>        {#if x.open === true}            ...        {/if}    {/each}{/await} 

And it will not work, since table is a @const. I want to find a clever and simple way to work this out. Is there any good practice I can use here instead of @const to not overload body of component with state variables?


Viewing all articles
Browse latest Browse all 1541

Trending Articles



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