Skip to main content

ReadonlyAtom

The ReadonlyAtom<T> type represents a read-only reactive state container that can be read and subscribed to, but cannot be directly modified.

Type Definition

Properties

get

Inherited from Readable<T>. Returns the current value of the atom. Type:

subscribe

Inherited from Subscribable<T>. Subscribes to changes in the atom’s value. Type:

Usage Examples

Creating a readonly atom

Derived readonly atoms

Subscribing to readonly atoms

Using as function parameter

When to Use

ReadonlyAtom<T> is useful when:
  • You want to expose an atom for reading without allowing external modifications
  • Creating derived/computed atoms that depend on other atoms
  • Enforcing read-only access in function parameters or return types
  • Building public APIs where internal state should not be directly modified
  • Atom - The writable version with a set method
  • Observer - The observer pattern for subscriptions
  • Subscription - The subscription object returned by subscribe
  • AtomOptions - Configuration options for creating atoms