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: 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```