useJoltEffect top-level property

JoltEffectHookCreator useJoltEffect
final

Creates a reactive effect hook that runs when dependencies change.

An effect is a side-effect function that automatically runs when any of its reactive dependencies change. Useful for logging, analytics, etc.

Parameters:

  • fn: 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
  • keys: Optional keys for hook memoization

Returns: An Effect that tracks dependencies and runs automatically

Example:

Widget build(BuildContext context) {
  final count = useSignal(0);

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

  return ElevatedButton(
    onPressed: () => count.value++,
    child: Text('Count: ${count.value}'),
  );
}

Implementation

final useJoltEffect = JoltEffectHookCreator._();