signal()
Create a reactive value that triggers updates when changed.
Signature
Section titled “Signature”function signal<T>(initialValue: T): Signal<T>Parameters
Section titled “Parameters”| Param | Type | Description |
|---|---|---|
initialValue | T | The initial value |
Returns
Section titled “Returns”Signal<T> with:
| Property | Type | Description |
|---|---|---|
.value | T | Read or write (triggers reactivity) |
.peek() | T | Read without tracking |
.set(value) | void | Set a new value |
.update(fn) | void | Update via function |
.subscribe(fn) | () => void | Subscribe to changes, returns unsubscribe |
Examples
Section titled “Examples”import { signal } from "@whisq/core";
const count = signal(0);count.value; // 0 (read — triggers tracking)count.value = 5; // (write — triggers updates)count.update(n => n + 1); // 6count.peek(); // 6 (read — no tracking)