useFlutterEffect top-level property

JoltFlutterEffectHookCreator useFlutterEffect
final

Creates a Flutter effect hook that schedules execution at frame end.

Flutter effects run automatically when their reactive dependencies change, but execution is scheduled at the end of the current Flutter frame. This batches multiple triggers within the same frame into a single execution, which is useful for UI-related side effects that should not interfere with frame rendering. Use onEffectCleanup inside the effect to register cleanup functions.

Parameters:

  • effect: The effect function to execute
  • lazy: Whether to run the effect immediately upon creation. If true, the effect will execute once immediately when created, then automatically re-run at frame end whenever its reactive dependencies change. If false (default), the effect will only run at frame end when dependencies change, not immediately upon creation.
  • onDebug: Optional debug callback for reactive system debugging

Returns: A FlutterEffect that tracks dependencies and runs at frame end

Example:

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

  useFlutterEffect(() {
    print('Count changed: ${count.value}'); // Executes at frame end

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

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

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

Implementation

final useFlutterEffect = JoltFlutterEffectHookCreator._();