Signal API reference for Signal in Semantic UI's reactivity system box API Reference
Categories

Signal

Create reactive values, read and write them, track their dependents, and derive new signals.

Creating

signal

signal(initialValue, options);

Creates a reactive value.

Parameters

NameTypeDescription
initialValueanyThe starting value
optionsobjectOptional configuration
Options
NameTypeDefaultDescription
safety'clone' | 'reference' | 'none''reference'Value-protection preset. See Signal Options
equalityfunctiondeep equalityDecides whether a new value differs from the current one. Snapshotted at construction
clonefunctionstructured cloneCopies values under safety: 'clone' and for change detection in mutate
idfunctionid ?? _id ?? hash ?? keyResolves an array item’s identity for the collection helpers
versionnumber0Seeds the change counter, for aligning with an external store’s revision

Example

Reading

get

signal.get();

Returns the current value and subscribes the running reaction.

Returns

The current value.

value

signal.value;
signal.value = newValue;

Property accessor for the signal. Reading subscribes the running reaction like get(), assigning sets the value like set().

Returns

The current value.

peek

signal.peek();

Returns the current value without subscribing. Under safety: 'clone' the result is still a defensive copy.

Returns

The current value, with no dependency registered.

Example

raw

signal.raw();

Returns the underlying stored value with no dependency tracking and no clone protection, even under safety: 'clone'.

raw() returns the actual stored object, not a copy. Mutating it bypasses change detection. Prefer peek() unless you specifically need the stored reference.

Returns

The live stored value.

Writing

set

signal.set(newValue);

Sets a new value, notifying dependents when it differs by the equality check.

Parameters

NameTypeDescription
newValueanyThe value to store

mutate

signal.mutate(mutationFn);

Updates the value through a callback. Return a new value to set it, or mutate the current value in place and reactivity fires only if it changed.

Small values are passed to the callback directly. Large values are passed as a write-tracking wrapper (it shows as Proxy(Object) in the console) so detection costs the writes you make, not the size of the value. The wrapper is only valid inside the callback, and changes are detected through it — writes made through outside references won’t fire at that scale.

Parameters

NameTypeDescription
mutationFnfunctionReceives the current value, optionally returns a new one

Usage

const items = signal(['apple', 'banana']);
// return a new value
items.mutate(list => [...list, 'cherry']);
// or mutate in place
items.mutate(list => { list.push('date'); });

Example

clear

signal.clear();

Sets the value to undefined, notifying dependents if it was not already undefined.

Example

Dependencies

depend

signal.depend();

Subscribes the running reaction without using the value, the same as writing const ignore = signal.get(). Use it when a reaction should re-run on a change but reads the value from elsewhere.

Example

notify

signal.notify();

Force-triggers dependents without changing the value, bypassing the equality check. Pair it with an in-place mutation under safety: 'reference' when the reference has not changed but dependents need to know.

Example

hasDependents

signal.hasDependents();

Reports whether any reaction is currently subscribed to this signal.

Returns

true if at least one reaction depends on the signal.

Example

version

signal.version;
signal.version = revision;

A monotonic integer that increments inside notify(), so it advances on every announced change: a set() to a non-equal value, an in-place mutation helper, or a force notify(). A set() that the equality check treats as a no-op leaves it unchanged. Reading it does not subscribe the running reaction.

Assign to it to realign with an external store’s revision. Seed the starting value with the version option on signal().

Returns

The current change count, starting at 0.

Example

Deriving

derive

signal.derive(computeFn, options);

Creates a new signal computed from this one, recomputing when this signal changes. Sugar for the free derive. For combining several sources see computed.

Parameters

NameTypeDescription
computeFnfunctionReceives this signal’s value, returns the derived value
optionsobjectOptional configuration, same shape as signal()

Returns

A new Signal holding the derived value.

Example

Previous
Reactivity
Next
Reaction