nanostores / query

⚡️ Powerful data fetching library for Nano Stores. TS/JS. Framework agnostic.
MIT License
228 stars 10 forks source link

Fetcher store always returns `loading: true` when used with svelte #22

Closed moaali closed 1 year ago

moaali commented 1 year ago

When using with Svelte I noticed that the query gets stuck at loading state even after the promise fulfils.

Screenshot 2023-10-29 at 9 55 20 PM

Reproduction: https://stackblitz.com/edit/svelte-spaceymen-3i3kjn

dkzlv commented 1 year ago

@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.