call method
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 executelazy: Whether to defer running the effect on creation. Iftrue, the effect will NOT run immediately and will not track dependencies until you callrunon the returned effect. Iffalse(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
@defineHook
Effect call(void Function() effect,
{bool lazy = false, JoltDebugOption? debug}) {
return useHook(_UseEffectHook(effect, lazy, debug));
}