svelte tip – Delay loading spinner

PHOTO EMBED

Tue Oct 17 2023 07:59:00 GMT+0000 (Coordinated Universal Time)

Saved by @passoul #svelte #delay-loading-spinner

const sleep = (ms: number) =>
	new Promise((resolve) =>
	setTimeout(resolve, ms),
);

{#await data.streamed.members}
	{#await sleep (200) then _}
	    Loading data
    {/await}
{:then value}
  {#each value as { id, full_name }}
  	{id}: {full_name}
  {/each}
{/await}
content_copyCOPY

Instead of showing loading spinner from the very first millisecond, wait for 200ms, then show. If the content loads before this 200ms, then no spinner! All with nested #await block 🔥