Skip to main content

Stores

Writable Store

src/lib/stores/count.js
import { writable } from 'svelte/store';

export const count = writable(0);

export { count as default };

Derived Store

src/lib/stores/doubled.js
import { derived } from 'svelte/store';
import count from '$lib/stores/count';

const doubled = derived(count, $count => $count * 2);

export { doubled as default };
src/lib/stores/sum.js
import { derived } from 'svelte/store';
import count from '$lib/stores/count';
import count2 from '$lib/stores/count2';

const sum = derived([count, count2], ([$count, $count2]) => $count + $count2);

export { sum as default };