lazy method

Effect lazy(
  1. void effect(), {
  2. JoltDebugFn? onDebug,
})

Creates an effect hook that runs immediately upon creation.

This method is a convenience constructor for creating an effect with lazy set to true. The effect will execute once immediately when created, then automatically re-run whenever its reactive dependencies change.

Parameters:

  • effect: The effect function to execute
  • onDebug: Optional debug callback for reactive system debugging

Returns: An Effect that executes immediately

Example:

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

  useEffect.lazy(() {
    print('Count is: ${count.value}'); // Executes immediately
  });

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

Implementation

Effect lazy(void Function() effect, {JoltDebugFn? onDebug}) {
  return useAutoDispose(() => Effect.lazy(effect, onDebug: onDebug));
}