useEffect top-level property

JoltEffectHookCreator useEffect
final

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

final useEffect = JoltEffectHookCreator._();