A stale-while-revalidate data fetching library for Svelte.
These components are still "experimental" (v0.x.x
).
Some of them are not tested as rigourously as it should be and none of them have been through code review.
Use them at your own risk and check that them do what you want them to do.
npm install @cicerchie/svelte-swr
<script>
import { useSWR } from "@cicerchie/svelte-swr";
const players = useSWR<PlayerList>();
$: players.update({
key: `players?page=${page}&filter=${JSON.stringify(filter)}`,
fn: () => playersService.list({ page, filter }),
});
</script>
{#if $players.isLoading}
Loading...
{:else if $players.error}
{$players.error}
{:else}
{#each $players.data.players as player (player.id)}
ID: {player.id}
{:else}
No players yet
{/each}
{/if}
Is automagically updated with each release and you can read it here.
onError
custom handlerany
!)routes
dir: it's a SvelteKit app!)