useWatcher top-level property

JoltWatcherHookCreator useWatcher
final

Creates a Watcher for the current hook scope.

fn receives the new and previous source values returned by sources. Use when to customize whether a change should trigger fn. Use JoltWatcherHookCreator.immediately when the callback should also run for the initial source values, or JoltWatcherHookCreator.once for a one-time reaction.

Widget build(BuildContext context) {
  final count = useSignal(0);

  useWatcher(
    () => count.value,
    (current, previous) {
      debugPrint('Count changed from $previous to $current');
    },
  );

  return Text('Count: ${count.value}');
}

Implementation

final useWatcher = JoltWatcherHookCreator._();