# useTransaction

Signature
`useTransaction(store?: Store): (callback: (txn: Transaction) => any) => any`

valdres-vue
Batch updates — subscribers fire once

Returns a function that runs a callback as a [transaction](https://valdres.dev/guides/transactions) on the current store: all updates apply atomically and subscribers fire once at the end. The callback receives `{ set, get, reset, del, unset }`.

## Usage

```vue
<script setup>
import { atom } from "valdres"
import { useTransaction } from "valdres-vue"

const firstNameAtom = atom("")
const lastNameAtom = atom("")

const txn = useTransaction()
const clear = () =>
    txn(({ reset }) => {
        reset(firstNameAtom)
        reset(lastNameAtom)
    })
</script>

<template>
    <button @click="clear">Clear</button>
</template>
```

Pass a store to target one explicitly: `useTransaction(myStore)`.

## See also

- [Transactions guide](https://valdres.dev/guides/transactions) — semantics, nesting, and performance
- [useStore](https://valdres.dev/vue/useStore) — access the current store
