Skip to main content

WritableAtom <T>

A writable Atom with a value that can be mutated via a setter interface.

Hierarchy

Callable

  • WritableAtom(): T

  • Returns T

Index

Properties

readonlyonDestroyed

onDestroyed: Signal<void>

Signals that the AtomEffect has been destroyed

Methods

asReadonly

  • asReadonly(): Atom<T>
  • Returns a readonly version of this atom. Readonly atom can be accessed to read their value but can't be changed using set, update or mutate methods.


    Returns Atom<T>

destroy

  • destroy(): void
  • Destroys the atom, notifies any dependents and calls onDestroy callback.


    Returns void

mutate

  • mutate(mutatorFn: (value: T) => void): void
  • Update the current value by mutating it in-place, and unconditionally notify any dependents.


    Parameters

    • mutatorFn: (value: T) => void

    Returns void

set

  • set(value: T): boolean
  • Directly set the atom to a new value, and notify any dependents.


    Parameters

    • value: T

    Returns boolean

update

  • update(updateFn: (value: T) => T): boolean
  • Update the value of the atom based on its current value, and notify any dependents.


    Parameters

    • updateFn: (value: T) => T

    Returns boolean