# toStore

Signature
`toStore<T>(state: Atom<T> | Selector<T>, store?: Store): Writable<T> | Readable<T>`

valdres-svelte
Svelte store contract for $-syntax

Bridges a valdres atom or selector into Svelte's store contract, for `$`-prefix auto-subscription and `bind:value={$count$}`. An atom yields a `Writable` (`subscribe` / `set` / `update`, all delegating to the store); a selector (or any read-only state) yields a read-only `Readable`. Prefer [fromState](https://valdres.dev/svelte/fromState) for new code — `toStore` exists for `$`-syntax interop.

## Usage

```svelte
<script lang="ts">
    import { atom } from "valdres"
    import { toStore } from "valdres-svelte"

    const countAtom = atom(0)
    const count$ = toStore(countAtom)
</script>

<p>Count: {$count$}</p>
<button onclick={() => ($count$ = 0)}>Zero</button>
<input type="number" bind:value={$count$} />
```

The `store` argument is optional and defaults to the context store (via [getValdresContext](https://valdres.dev/svelte/getValdresContext)), so it can be omitted during component initialization — consistent with every other primitive.

## See also

- [fromState](https://valdres.dev/svelte/fromState) — rune-based reactive box (preferred)
- [setValdresContext](https://valdres.dev/svelte/setValdresContext) — provide a store to the component tree
