<script setup lang="ts">
import { createAtom, useAtom, useSelector } from '@tanstack/vue-store'
const countAtom = createAtom(0)
const count = useSelector(countAtom)
const [editableCount, setEditableCount] = useAtom(countAtom)
</script>
<template>
<main>
<h1>Vue Atom Hooks</h1>
<p>
This example creates a module-level atom and reads and updates it with the
Vue hooks.
</p>
<p>Total: {{ count }}</p>
<div>
<button type="button" @click="countAtom.set((prev: number) => prev + 1)">
Increment
</button>
<button type="button" @click="countAtom.set(0)">Reset</button>
</div>
<div>
<p>Editable count: {{ editableCount }}</p>
<button
type="button"
@click="setEditableCount((prev: number) => prev + 5)"
>
Add 5 with useAtom
</button>
</div>
</main>
</template>