• Creates a reactive signal that can hold and notify changes to a value.

    Signals are the fundamental reactive primitive. They store a value and notify subscribers when the value changes. Reading a signal automatically tracks dependencies when inside an effect or computed.

    Isomorphic: Works identically across all JavaScript runtimes. Performance: Optimized for frequent reads and infrequent writes. Memory: Automatic cleanup when all subscribers are removed.

    Type Parameters

    • T

    Parameters

    • Optionalinitial: T

      The initial value of the signal

    Returns (() => T)

    Signal accessor with methods

      • (): T
      • Returns T

    // Create signal
    const count = signal(0);

    // Read value (tracks dependency if in effect/computed)
    console.log(count()); // 0

    // Update value
    count.set(5);
    count.update(n => n + 1); // 6

    // Read without tracking
    console.log(count.peek()); // 6

    // Subscribe to changes
    const unsub = count.subscribe(value => console.log('New:', value));
    count.set(10); // Logs: "New: 10"
    unsub(); // Clean up
    // Isomorphic usage - same code everywhere
    const data = signal(null);

    // Works in Node.js
    if (typeof process !== 'undefined') {
    data.set({ platform: 'node' });
    }

    // Works in browser
    if (typeof window !== 'undefined') {
    data.set({ platform: 'browser' });
    }

    // Works in Deno/Bun
    data.set({ platform: 'universal' });