effect function

void Function() effect(
  1. void cb(), {
  2. String? debugLabel,
})

Runs a reactive side-effect callback cb whenever any accessed signal changes.

Returns a disposer function that cancels future executions of the effect.

Example:

final count = signal(0);
final dispose = effect(() {
  print('Count is now: ${count.value}');
});
count.value = 1; // prints "Count is now: 1"
dispose(); // Stops the effect

Implementation

void Function() effect(void Function() cb, {String? debugLabel}) {
  return sf.effect(cb, debugLabel: debugLabel);
}