On This Page
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
| Name | Type | Description |
|---|---|---|
| initialValue | any | The starting value |
| options | object | Optional configuration |
Options
| Name | Type | Default | Description |
|---|---|---|---|
| safety | 'clone' | 'reference' | 'none' | 'reference' | Value-protection preset. See Signal Options |
| equality | function | deep equality | Decides whether a new value differs from the current one. Snapshotted at construction |
| clone | function | structured clone | Copies values under safety: 'clone' and for change detection in mutate |
| id | function | id ?? _id ?? hash ?? key | Resolves an array item’s identity for the collection helpers |
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.
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
| Name | Type | Description |
|---|---|---|
| newValue | any | The 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.
Parameters
| Name | Type | Description |
|---|---|---|
| mutationFn | function | Receives the current value, optionally returns a new one |
Usage
const items = signal(['apple', 'banana']);
// return a new valueitems.mutate(list => [...list, 'cherry']);
// or mutate in placeitems.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
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
| Name | Type | Description |
|---|---|---|
| computeFn | function | Receives this signal’s value, returns the derived value |
| options | object | Optional configuration, same shape as signal() |
Returns
A new Signal holding the derived value.