Open History to see the last commit
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>
46)
47```