useEffect top-level property
_JoltEffectHookCreatorImpl
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 executelazy: Whether to run the effect immediately upon creation. Iftrue, the effect will execute once immediately when created, then automatically re-run whenever its reactive dependencies change. Iffalse(default), the effect will only run when dependencies change, not immediately upon creation.onDebug: Optional debug callback for reactive system debugging
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 = _JoltEffectHookCreatorImpl();