Core Functions
signal
Creates a reactive signal that can be subscribed to. Re-exported from@preact/signals-core.
T
required
The initial value
Signal<T>
A signal object with
.value property and .peek() methodUsage Example
computed
Creates a computed signal that automatically updates when its dependencies change.() => T
required
Function that computes the value
(a: T, b: T) => boolean
Optional equality comparator to prevent unnecessary updates
ReadonlySignal<T>
A readonly signal that updates when dependencies change
Usage Example
effect
Runs a side effect function whenever its dependencies change. Re-exported from@preact/signals-core.
() => void | CleanupFunction
required
Effect function that runs when dependencies change. Can optionally return a cleanup function.
() => void
A function to stop the effect and run cleanup
Usage Example
effects
Runs multiple effects and returns a single cleanup function.Effect[]
required
Multiple effect functions to run
CleanupFunction
A function that cleans up all effects
Usage Example
batch
Batches multiple signal updates to prevent unnecessary re-renders. Re-exported from@preact/signals-core.
() => void
required
Function that performs multiple signal updates
Usage Example
untracked
Reads a signal value without subscribing to it. Re-exported from@preact/signals-core.
() => T
required
Function that reads signals
T
The return value of the function
Usage Example
Decorators
@reactive
Decorator that makes a class accessor reactive using signals.Usage Example
@derived
Decorator that makes a getter computed, caching its result and only recomputing when dependencies change.Usage Example
@enumerable
Decorator that controls whether a property is enumerable.boolean
default:"true"
Whether the property should be enumerable
Usage Example
Utilities
deepEqual
Performs deep equality comparison between two values.T
required
First value
T
required
Second value
boolean
True if values are deeply equal
Usage Example
snapshot
Creates a plain object snapshot of a reactive object without triggering subscriptions.T extends object
required
The reactive object to snapshot
T
A plain object copy with all enumerable properties
Usage Example
Advanced Utilities
ValueHistory
A class that tracks current, previous, and initial values with reactive updates.T
required
The default/initial value
(a: T, b: T) => boolean
default:"Object.is"
Equality comparator for detecting changes
Properties
T
The current value (reactive)
T | undefined
The previous value, or undefined if not yet changed (reactive)
T
The initial value (reactive)
Methods
reset
Resets to the default value or a new value.Usage Example
WeakStore
A weak reference store that associates values with object keys and identifiers.Methods
get
Retrieves a value from the store.WeakKey | undefined
required
The weak key (object reference)
Key
required
The identifier within that key’s map
Value | undefined
The stored value, or undefined if not found
set
Stores a value in the store.WeakKey | undefined
required
The weak key (object reference)
Key
required
The identifier within that key’s map
Value
required
The value to store
clear
Clears all values associated with a key.WeakKey | undefined
required
The weak key to clear