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

useAtom.md

47 lines864 Bytes

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