Fetcher store always returns `loading: true` when used with svelte
moaali opened this issue · 1 comments
moaali commented
When using with Svelte I noticed that the query gets stuck at loading state even after the promise fulfils.
Reproduction: https://stackblitz.com/edit/svelte-spaceymen-3i3kjn
dkzlv commented
@moaali Hey!
No bug here: you destructure the values once and instantly unsubscribe. If you want reactivity, you should pick a different syntax. The following will work:
<script>
import {posts} from './stores/posts'
$: ({loading, data} = $posts);
</script>
<div>
{#if loading}
loading...
{:else if data}
{data.title}
{:else}
error
{/if}
</div>
In any case, I recommend getting a fresh look at Svelte's $:
statement.