Logosolidart

Signals

Signals are the cornerstone of reactivity in solidart. They contain values that change over time; when you change a signal's value, it automatically updates anything that uses it.

To create a signal, let's import createSignal and call it like this:

Next create the signal with:

final counter = createSignal(0);
// or
final counter = Signal(0);

The argument passed to the create call is the initial value, and the return value is the signal.

To retrieve the current signal value use:

counter.value; // 0
// or
counter(); // 0

To update the current signal value you can use:

counter.value++; // increase by 1
// or 
counter.value = 5; // sets the value to 5
// or
counter.set(2); // sets the value to 2
// or 
counter.update((v) => v * 2); // update based on the current value
Don't forget to call the dispose() method when you no longer need the signal.
counter.dispose();