Atom<T>
Reactive state container interface
Properties
Section titled “Properties”Name | Type | Description |
---|---|---|
get | () => T | Get the current value. |
set | (value: T) => void | Set a new value. |
subscribe | (listener: Listener<T>) => () => void | Subscribe to value changes. |
Example
Section titled “Example”const count = atom(0);count.set(1);console.log(count.get()); // 1const unsubscribe = count.subscribe((val) => console.log(val));