call method

  1. @defineHook
Effect call(
  1. void effect(), {
  2. bool lazy = false,
  3. JoltDebugOption? debug,
})

Creates an effect hook that runs in response to reactive dependencies.

Effects run automatically when their reactive dependencies change. Use onEffectCleanup inside the effect to register cleanup functions.

Parameters:

  • effect: The effect function to execute
  • lazy: Whether to defer running the effect on creation. If true, the effect will NOT run immediately and will not track dependencies until you call run on the returned effect. If false (default), the effect runs immediately on creation and then re-runs whenever its reactive dependencies change.
  • debug: Optional debug options

Returns: An Effect that tracks dependencies and runs automatically

Example:

setup(context, props) {
  final count = useSignal(0);

  useEffect(() {
    print('Count changed: ${count.value}');

    final timer = Timer.periodic(Duration(seconds: 1), (_) {
      count.value++;
    });

    onEffectCleanup(() => timer.cancel());
  });

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

Implementation

@defineHook
Effect call(void Function() effect,
    {bool lazy = false, JoltDebugOption? debug}) {
  return useHook(_UseEffectHook(effect, lazy, debug));
}