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

useAtom.md

47 lines851 Bytes

1---
2id: useAtom
3title: useAtom
4---
5​
6```ts
7function useAtom<TValue>(atom, options?): [TValue, (fn) => void & (value) => void];
8```
9​
10Defined in: node\_modules/.pnpm/@tanstack+preact-store@0.13.2\_preact@10.29.8/node\_modules/@tanstack/preact-store/dist/useAtom.d.ts:22
11​
12Returns the current atom value together with a stable 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\[`TValue`, (`fn`) => `void` & (`value`) => `void`\]
36​
37## Example
38​
39```tsx
40const [count, setCount] = useAtom(countAtom)
41​
42return (
43 <button type="button" onClick={() => setCount((prev) => prev + 1)}>
44 {count}
45 </button>
47```