atom

See source code

Creates a new Atom.

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

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

Example

const name = atom("name", "John");

name.get(); // 'John'

name.set("Jane");

name.get(); // 'Jane'

Parameters

NameDescription

name

string;

initialValue

Value;

options

AtomOptions<Value, Diff>;

Returns

Atom<Value, Diff>;
Prev
useViewportHeight
Next
computed