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

useCreateAtom.md

84 lines1.7 KB

1---
2id: useCreateAtom
3title: useCreateAtom
4---
5​
6## Call Signature
7​
8```ts
9function useCreateAtom<T>(getValue, options?): ReadonlyAtom<T>;
10```
11​
12Defined in: node\_modules/.pnpm/@tanstack+react-store@0.11.0\_react-dom@19.2.8\_react@19.2.8\_\_react@19.2.8/node\_modules/@tanstack/react-store/dist/useCreateAtom.d.ts:16
13​
14Creates a stable atom instance for the lifetime of the component.
15​
16Pass an initial value to create a writable atom, or a getter function to
17create a readonly derived atom. This hook mirrors the overloads from
18[createAtom](createAtom.md), but ensures the atom is only created once per mount.
19​
20### Type Parameters
21​
22#### T
23​
24`T`
25​
26### Parameters
27​
28#### getValue
29​
30(`prev?`) => `T`
31​
32#### options?
33​
34[`AtomOptions`](../interfaces/AtomOptions.md)\<`T`\>
35​
36### Returns
37​
38[`ReadonlyAtom`](../interfaces/ReadonlyAtom.md)\<`T`\>
39​
40### Example
41​
42```tsx
43const countAtom = useCreateAtom(0)
44```
45​
46## Call Signature
47​
48```ts
49function useCreateAtom<T>(initialValue, options?): Atom<T>;
50```
51​
52Defined in: node\_modules/.pnpm/@tanstack+react-store@0.11.0\_react-dom@19.2.8\_react@19.2.8\_\_react@19.2.8/node\_modules/@tanstack/react-store/dist/useCreateAtom.d.ts:17
53​
54Creates a stable atom instance for the lifetime of the component.
55​
56Pass an initial value to create a writable atom, or a getter function to
57create a readonly derived atom. This hook mirrors the overloads from
58[createAtom](createAtom.md), but ensures the atom is only created once per mount.
59​
60### Type Parameters
61​
62#### T
63​
64`T`
65​
66### Parameters
67​
68#### initialValue
69​
70`T`
71​
72#### options?
73​
74[`AtomOptions`](../interfaces/AtomOptions.md)\<`T`\>
75​
76### Returns
77​
78[`Atom`](../interfaces/Atom.md)\<`T`\>
79​
80### Example
81​
82```tsx
83const countAtom = useCreateAtom(0)
84```