Function: useCreateSignal()
useCreateSignal<
T>(initialValue): [SignalGetter<T>,SignalSetter<T>]
Defined in: src/core/services/reactive.service.ts:55
Creates a reactive signal with a getter and setter.
The getter is callable and also exposes a useSubscribe method for
listening to value changes. The setter accepts either a direct value or
an updater function.
Type Parameters
T
T
The signal value type.
Parameters
initialValue
T
The initial value of the signal.
Returns
[SignalGetter<T>, SignalSetter<T>]
A tuple of [getter, setter].
Example
const [count, setCount] = useCreateSignal(0);
count(); // 0
setCount(1);
count(); // 1
setCount(prev => prev + 1);
count(); // 2
const unsub = count.useSubscribe((newVal, oldVal) => {
console.log(`${oldVal} -> ${newVal}`);
});