lazy method

  1. @defineHook
Effect lazy(
  1. void effect(), {
  2. JoltDebugOption? debug,
})

Creates an effect hook that does not run automatically upon creation.

This method is a convenience constructor for creating an effect with lazy set to true. The effect will not execute until you call run. After the first manual run, it will track dependencies and re-run when they change.

Parameters:

  • effect: The effect function to execute
  • debug: Optional debug options

Returns: An Effect that starts in deferred mode

Example:

setup(context, props) {
  final count = useSignal(10);
  final effect = useEffect.lazy(() {
    print('Count is: ${count.value}');
  });

  onMounted(effect.run);

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

Implementation

@defineHook
Effect lazy(void Function() effect, {JoltDebugOption? debug}) {
  return useHook(_UseEffectHook(effect, true, debug));
}