Skip to content

@jsvision/ui / signal

Function: signal()

signal<T>(initial, options?): Signal<T>

Defined in: ui/src/reactive/signal.ts:40

Create a writable reactive value.

Type Parameters

T

T

Parameters

initial

T

The initial value.

options?

SignalOptions<T>

Optional equality policy — see SignalOptions.

Returns

Signal<T>

A callable accessor: call it to read (and, inside a tracked computation, subscribe); .set(v) replaces the value; .update(fn) derives the next value from the previous; .peek() reads the current value without subscribing.

Example

ts
import { signal, effect } from '@jsvision/ui';

const count = signal(0);
effect(() => console.log('count is', count())); // logs 0, then re-runs on each change
count.set(1);                 // effect re-runs → "count is 1"
count.update((n) => n + 10);  // effect re-runs → "count is 11"
count.set(11);                // equal value → no re-run
count.peek();                 // 11, read without subscribing