상태값을 전역으로 관리하려면...store
import { writable } from 'svelte/store'
export const count = writable(0);
<script>
import { count } from '../store.js'
const onIncrement = () => {
$count += 1;
}
</script>
<button on:click={onIncrement}>+</button>
<script>
import { count } from '../store.js'
const onDecrement = () => {
$count -= 1;
}
</script>
<button on:click={onDecrement}>-</button>
<script>
import { count } from '../store.js'
</script>
<h3>현재 count는 { $count} 입니다.</h3>

import { writable } from 'svelte/store'
function createCount() {
const { subscribe, set, update } = writable(0);
return {
subscribe,
increment: () => update(count =>count + 1),
decrement: () => update(count => count - 1),
reset: () => set(0)
};
}
export const count = createCount();
<script>
import { count } from '../store.js'
const onIncrement = () => {
count.increment(); // 사용자 정의 함수
}
</script>
<button on:click={onIncrement}>+</button>
<script>
import { count } from '../store.js'
const onDecrement = () => {
count.decrement(); // 사용자 정의 함수
}
</script>
<button on:click={onDecrement}>-</button>
