Skip to content
Source
Sign inSign up
TanStack/form
Open History to see the last commit

useAtom.md

44 lines860 Bytes

1---
2id: useAtom
3title: useAtom
4---
5​
6```ts
7function useAtom<TValue>(atom, options?): [Readonly<Ref<TValue, TValue>>, (fn) => void & (value) => void];
8```
9​
10Defined in: node\_modules/.pnpm/@tanstack+vue-store@0.11.1\_vue@3.6.0-rc.9\_typescript@6.0.3\_/node\_modules/@tanstack/vue-store/dist/useAtom.d.ts:20
11​
12Returns the current atom ref together with a setter.
13​
14Use this when a component needs to both read and update the same writable
15atom.
16​
17## Type Parameters
18​
19### TValue
20​
21`TValue`
22​
23## Parameters
24​
25### atom
26​
27[`Atom`](../interfaces/Atom.md)\<`TValue`\>
28​
29### options?
30​
31[`UseSelectorOptions`](../interfaces/UseSelectorOptions.md)\<`TValue`\>
32​
33## Returns
34​
35\[`Readonly`\<`Ref`\<`TValue`, `TValue`\>\>, (`fn`) => `void` & (`value`) => `void`\]
36​
37## Example
38​
39```ts
40const [count, setCount] = useAtom(countAtom)
41​
42setCount((prev) => prev + 1)
43console.log(count.value)
44```