Skip to main content

atom()

Creates a new Atom.

An Atom is a signal that can be updated directly by calling Atom.set or Atom.update.

Example

const name = atom('name', 'John')

name.value // 'John'

name.set('Jane')

name.value // 'Jane'

Signature

atom<Value, Diff>(name: string, initialValue: Value, options?: AtomOptions<Value, Diff>): Atom<Value, Diff>;

Type parameters

  • Value
  • Diff = unknown

Parameters

NameTypeDescription
namestringA name for the signal. This is used for debugging and profiling purposes, it does not need to be unique.
initialValueValueThe initial value of the signal.
options?AtomOptions<Value, Diff>The options to configure the atom. See AtomOptions.

Returns

Atom<Value, Diff>

Defined in: signia/src/Atom.ts:173