Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Svelte: Modify Await Reference?

Say I have:

{#await showMinePromise}
    <p>...Loading</p>
{:then entries}    
    // do stuff    
{/await}

Is there a way to update the entries variable to add in items (as when the user adds something, etc)? By that I mean manually insert an item into the array external to the await -- no call to update the promise.

like image 641
mtyson Avatar asked Oct 13 '25 04:10

mtyson


1 Answers

You can do that :

<script>

  let fetchSomething = ... // some Promise
  let datas;

  fetchSomething.then(r => datas = r);
</script>

{#await fetchSomething}
  <p>Loading</p>
{:then}
  // use datas. it's updatable
{/await}

like image 101
Jérémie B Avatar answered Oct 14 '25 19:10

Jérémie B