Open History to see the last commit
1---
2id: useCreateAtom
3title: useCreateAtom
4---
5β
6## Call Signature
7β
8```ts
9function useCreateAtom<T>(getValue, options?): ReadonlyAtom<T>;
10```
11β
12Defined in: [packages/react-store/src/useCreateAtom.ts:19](https://github.com/TanStack/store/blob/main/packages/react-store/src/useCreateAtom.ts#L19)
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
18createAtom, 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`\<`T`\>
35β
36### Returns
37β
38`ReadonlyAtom`\<`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: [packages/react-store/src/useCreateAtom.ts:23](https://github.com/TanStack/store/blob/main/packages/react-store/src/useCreateAtom.ts#L23)
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
58createAtom, 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`\<`T`\>
75β
76### Returns
77β
78`Atom`\<`T`\>
79β
80### Example
81β
82```tsx
83const countAtom = useCreateAtom(0)
84```