Overview
Theatom() function is the core primitive for storing and updating mutable state in Reatom. Atoms can be called as functions to read their current value or updated using the .set() method.
Import
Signature
Parameters
T | (() => T)
The initial state value, or a function that returns the initial state. If a function is provided, it will be called once during atom initialization.
string
Optional name for the atom. Useful for debugging and dev tools. If not provided, an auto-generated name will be used.
Returns
Atom<T>
An atom instance with the following interface:
Examples
Basic Usage
Using a Function for Initial State
Subscribing to Changes
Atom Without Initial State
Complex State
Type Information
Atom Interface
AtomLike Interface
Related
- computed() - Create derived state that automatically recalculates
- action() - Create logic and side effect containers
- extend() - Add functionality to atoms
- effect() - Create reactive side effects