Store Docs
API Reference
Store API Reference
- Store
- ReadonlyStore
- Atom
- AtomOptions
- BaseAtom
- InternalBaseAtom
- InternalReadonlyAtom
- InteropSubscribable
- Readable
- ReadonlyAtom
- StoreActionsApi
- Subscribable
- Subscription
- AnyAtom
- Observer
- Selection
- StoreAction
- StoreActionMap
- StoreActionsFactory
- batch
- createAsyncAtom
- createAtom
- createStore
- flush
- shallow
- toObserver
- createStoreContext
- useCreateAtom
- useCreateStore
- useSelector
- useSetValue
- useAtom
- useStoreActions
- _useStore (experimental)
- useStore (deprecated)
- UseSelectorOptions
AI/LLM: This documentation page is available in plain markdown format at/store/latest/docs/framework/react/reference/functions/useCreateAtom.md
Store API Reference
useCreateAtom
Call Signature#
ts
function useCreateAtom<T>(getValue, options?): ReadonlyAtom<T>;Defined in: packages/react-store/src/useCreateAtom.ts:17
Creates a stable atom instance for the lifetime of the component.
Pass an initial value to create a writable atom, or a getter function to create a readonly derived atom. This hook mirrors the overloads from createAtom, but ensures the atom is only created once per mount.
Type Parameters#
T#
T
Parameters#
getValue#
(prev?) => T
options?#
AtomOptions<T>
Returns#
ReadonlyAtom<T>
Example#
tsx
const countAtom = useCreateAtom(0)Call Signature#
ts
function useCreateAtom<T>(initialValue, options?): Atom<T>;Defined in: packages/react-store/src/useCreateAtom.ts:21
Creates a stable atom instance for the lifetime of the component.
Pass an initial value to create a writable atom, or a getter function to create a readonly derived atom. This hook mirrors the overloads from createAtom, but ensures the atom is only created once per mount.
Type Parameters#
T#
T
Parameters#
initialValue#
T
options?#
AtomOptions<T>
Returns#
Atom<T>
Example#
tsx
const countAtom = useCreateAtom(0)