# useStore

Signature
`useStore(): Store`

valdres-react
Access the current store instance

Returns the current valdres store from the nearest `<Provider>`, or the default global store if no Provider is present. Useful when you need direct store access for imperative operations.

## Usage

```tsx
import { useStore } from "valdres-react"

function Debug() {
    const store = useStore()

    const handleClick = () => {
        // Direct store access for imperative operations
        const value = store.get(myAtom)
        console.log("Current value:", value)
    }

    return <button onClick={handleClick}>Log value</button>
}
```

## Transactions

Access the store to perform batched updates:

```tsx
function BatchUpdate() {
    const store = useStore()

    const handleReset = () => {
        store.txn(set => {
            set(nameAtom, "")
            set(emailAtom, "")
            set(ageAtom, 0)
        })
    }

    return <button onClick={handleReset}>Reset all</button>
}
```

## See also

- [Provider](https://valdres.dev/react/Provider) — provide a store to a React subtree
- [store](https://valdres.dev/valdres/store) — create a store instance
